AS3 socket cannot load data from - actionscript-3

I have searched internet for a lot of times but could not find any clue. I am using sockets to connect to socket server. (Also we tryed different socket policy files, but none worked)
private var SERVER_URL : String = "http://192.168.0.105";
private var PORT_NUMBER : int = 1435;
private var _socket : Socket;
// signal
private var _signal : Signal;
public function BackendService()
{
// nastavenie socketu
_socket = new Socket();
_socket.addEventListener(Event.CONNECT, connectHandler);
_socket.addEventListener(Event.CLOSE, closeHandler);
_socket.addEventListener(ErrorEvent.ERROR, errorHandler);
_socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
_socket.addEventListener(ProgressEvent.SOCKET_DATA, HandleMsgFromServer); // ak pride sprava zo serveru
Security.allowDomain("*");
Security.allowInsecureDomain("*");
Security.loadPolicyFile("http://192.168.0.105:8000/crossdomain.xml");
// signal na dispatchovanie eventov
_signal = new Signal();
connect(); // I am doing it from other class, but for sake of example, I am calling from here
}
public function connect():void
{
_socket.connect(SERVER_URL, PORT_NUMBER);
}
My crossdomain - socket policy file are sitting on port 8000 and looks like this:
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
I am getting this error:
Error #2044: Unhandled securityError:. text=Error #2048: Security
sandbox violation:
file:///C:/projects/TennisHeroes/bin/TennisHeroes.swf cannot load data
from http://192.168.0.105:1435.
Thank you very much for any advice!

Related

Failed to fetch while error reading CSV file ASP.NET

I'm trying to read .CSV file and instead of the read lines, Swagger outputs
Failed to fetch.
Possible Reasons:
CORS
Network Failure
URL scheme must be "http" or "https" for CORS request.
In my opinion, even Visual Studio crashed, the application immediately stops working
//Controller
[ApiController]
[Route("[controller]")]
public class HomeController: ControllerBase
{
private readonly ICSVService _csvService;
public HomeController(ICSVService csvService)
{
_csvService = csvService;
}
[HttpPost("read-csv")]
public async Task<IActionResult> GetCSV([FromForm] IFormFileCollection file)
{
var dataFromFile = _csvService.ReadCSV<Values>(file[0].OpenReadStream());
return Ok(dataFromFile);
}
}
// Reader
public class CSVServise : ICSVService
{
public IEnumerable<T> ReadCSV<T>(Stream file)
{
var reader = new StreamReader(file);
var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
var records = csv.GetRecords<T>();
return records;
}
}
// Program.cs
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms /aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<ICSVService, CSVServise>();
builder.Services.AddCors();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors(builder => builder.AllowAnyOrigin());
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
My launchSettings.json
I thought enabling CORS would help, but it doesn't seem to have worked. And now I have no idea - what could be the problem?

RED5 - cannot call RED5 method/ function from flash client Air for IOS

I have a NetConnection in flash client that connects to the RED5 server with no problems but when i want to call a RED5 method/ function i keep get this error:
I have set the nc.client = this, but still i get an error.
ReferenceError: Error #1069: Property perform not found on HUGT and there is no default value.
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetConnection was unable to invoke callback perform. error=ReferenceError: Error #1069: Property perform not found on HUGT and there is no default value.
at HUGT/setUpRed5Connection()[/Users/trikampatel/Documents/fb/HUGT.as:89]
at HUGT/onAddedToStage()[/Users/trikampatel/Documents/fb/HUGT.as:175]
The code I'm using is below:
private function setUpRed5Connection(){
nc = new NetConnection();
nc.client = this;
nc.connect("rtmp://192.168.1.4/RED5Hugt");
nc.addEventListener(NetStatusEvent.NET_STATUS,getStream);
}
public function onBWCheck(...rest):Number
{
return 0;
}
public function onBWDone(...rest):void
{
var p_bw:Number;
if (rest.length > 0){
p_bw = rest[0];
}
trace("bandwidth = " + p_bw + " Kbps.");
}
function getStream(e:NetStatusEvent):void
{
//connectCamera();
nsIn = new NetStream(nc);
nsOut = new NetStream(nc);
//vid.attachNetStream(nsIn);
//nsIn.play("tester");
//nsOut=new NetStream(nc);
//netOut.attachAudio(mic);
//nsOut.attachCamera(cam);
//nsOut.publish("tester", "live");
}
public function performSend(country:String, uid:String):void{
trace("cdcdcdcdcdcdcdcdcdcdc");
var nr:Responder = new Responder(netResponderHandler);
nc.call("perform", nr, uid, country);
}
function netResponderHandler(serverResult:Object)
{
trace("The result is " + serverResult);
}
RED5 server:
public long perform(Object[] params){
System.out.println((String)params[0] + " " + (String) params[1]);
User u = this.getCountryPerformer(country).getUser(uid);
long yt = u.ticket;
return yt;
}
UPDATE
Unusual behaviour now, i created a perform function in my action script class and the nc.call("perform", nr, val, val2) is calling the perform method in my action script class rather than the perform method in the red5 application adapter class, here is the function i created that gets called in the action script:
public function perform(obj:Object, obj2:Object){
trace("dzddzdzd");
}

What does this socket error mean?

First of all thanks to everyone that answers questions on here. I have used this forum as a java bible. This is a homework problem and here is the assignment:
Write a program in Java that uses sockets to connect to a web server on port 80, requests a web page using GET of the HTTP protocol, and displays the resulting HTML
Not sure if I am doing this right or not. I have a very limited understanding of java. Most of this is from tutorials I have been going through. Any website links would be greatly appreciated.
Here is my error message:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from java.net.Socket to Socket
The method getInputStream() is undefined for the type Socket
Here is my code:
import java.io.*;
import java.net.*;
public class Server
{
public static void main(String[] args) throws Exception
{
Server SERVER = new Server();
SERVER.run();
}
public void run() throws Exception
{
ServerSocket one = new ServerSocket(80);
//these are the two lines of code it is warning about
Socket myskt = one.accept();
InputStreamReader IR = new InputStreamReader(myskt.getInputStream());
//end of warnings
BufferedReader BR = new BufferedReader(IR);
String message = BR.readLine();
System.out.println(message);
if (message != null)
{
PrintStream PS = new PrintStream(System.out);
PS.println("Message Received");
}
URL website = new URL("www.dogs.com");
URLConnection yc = website.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in .readLine()) != null)
System.out.println(inputLine);
one.close();
}
// TODO Auto-generated method stub
}
The issue is that our code is not well-formed - you have a compilation error. My guess is that you have a class Socket in the same package as the class you're compiling, or a left-over class file (Socket.class) on the classpath. When the compiler runs, it uses the package local version of Socket, which is not the same type as java.net.Socket - hence the exception.
To resolve thisuse the fully qualified name java.net.Socket when declaring myskt

System.Net.WebException: The request failed with HTTP status 400: Bad Request. calling a webservice dynamically

Iam calling a web service through my web service dynamically. I stored serviceName, MethodToCall, and array of parameters in my database table and execute these two methods to call a dynamic service url with .asmx extention and its method without adding its reference in my app. It works fine.
Following code is here.
public string ShowThirdParty(String strURL, String[] Params, String MethodToCall, String ServiceName)
{
String Result = String.Empty;
//Specify service Url without ?wsdl suffix.
//Reference urls for code help
///http://www.codeproject.com/KB/webservices/webservice_.aspx?msg=3197985#xx3197985xx
//http://www.codeproject.com/KB/cpp/CallWebServicesDynamic.aspx
//String WSUrl = "http://localhost/ThirdParty/WebService.asmx";
String WSUrl = strURL;
//Specify service name
String WSName = ServiceName;
//Specify method name to be called
String WSMethodName = MethodToCall;
//Parameters passed to the method
String[] WSMethodArguments = Params;
//WSMethodArguments[0] = "20500";
//Create and Call Service Wrapper
Object WSResults = CallWebService(WSUrl, WSName, WSMethodName, WSMethodArguments);
if (WSResults != null)
{
//Decode Results
if (WSResults is DataSet)
{
Result += ("Result: \r\n" + ((DataSet)WSResults).GetXml());
}
else if (WSResults is Boolean)
{
bool BooleanResult = (Boolean)WSResults;
if(BooleanResult)
Result += "Result: \r\n" + "Success";
else
Result += "Result: \r\n" + "Failure";
}
else if (WSResults.GetType().IsArray)
{
Object[] oa = (Object[])WSResults;
//Retrieve a property value withour reflection...
PropertyDescriptor descriptor1 = TypeDescriptor.GetProperties(oa[0]).Find("locationID", true);
foreach (Object oae in oa)
{
Result += ("Result: " + descriptor1.GetValue(oae).ToString() + "\r\n");
}
}
else
{
Result += ("Result: \r\n" + WSResults.ToString());
}
}
return Result;
}
public Object CallWebService(string webServiceAsmxUrl,
string serviceName, string methodName, string[] args)
{
try
{
System.Net.WebClient client = new System.Net.WebClient();
Uri objURI = new Uri(webServiceAsmxUrl);
//bool isProxy = client.Proxy.IsBypassed(objURI);
//objURI = client.Proxy.GetProxy(objURI);
//-Connect To the web service
// System.IO.Stream stream = client.OpenRead(webServiceAsmxUrl + "?wsdl");
string ccc = webServiceAsmxUrl + "?wsdl";// Connect To the web service System.IO.
//string wsdlContents = client.DownloadString(ccc);
string wsdlContents = client.DownloadString(ccc);
XmlDocument wsdlDoc = new XmlDocument();
wsdlDoc.InnerXml = wsdlContents;
System.Web.Services.Description.ServiceDescription description = System.Web.Services.Description.ServiceDescription.Read(new XmlNodeReader(wsdlDoc));
//Read the WSDL file describing a service.
// System.Web.Services.Description.ServiceDescription description = System.Web.Services.Description.ServiceDescription.Read(stream);
//Load the DOM
//--Initialize a service description importer.
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap12"; //Use SOAP 1.2.
importer.AddServiceDescription(description, null, null);
//--Generate a proxy client.
importer.Style = ServiceDescriptionImportStyle.Client;
//--Generate properties to represent primitive values.
importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;
//Initialize a Code-DOM tree into which we will import the service.
CodeNamespace codenamespace = new CodeNamespace();
CodeCompileUnit codeunit = new CodeCompileUnit();
codeunit.Namespaces.Add(codenamespace);
//Import the service into the Code-DOM tree.
//This creates proxy code that uses the service.
ServiceDescriptionImportWarnings warning = importer.Import(codenamespace, codeunit);
if (warning == 0)
{
//--Generate the proxy code
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
//--Compile the assembly proxy with the
// appropriate references
string[] assemblyReferences = new string[] {
"System.dll",
"System.Web.Services.dll",
"System.Web.dll",
"System.Xml.dll",
"System.Data.dll"};
//--Add parameters
CompilerParameters parms = new CompilerParameters(assemblyReferences);
parms.GenerateInMemory = true; //(Thanks for this line nikolas)
CompilerResults results = provider.CompileAssemblyFromDom(parms, codeunit);
//--Check For Errors
if (results.Errors.Count > 0)
{
foreach (CompilerError oops in results.Errors)
{
System.Diagnostics.Debug.WriteLine("========Compiler error============");
System.Diagnostics.Debug.WriteLine(oops.ErrorText);
}
throw new Exception("Compile Error Occured calling WebService.");
}
//--Finally, Invoke the web service method
Object wsvcClass = results.CompiledAssembly.CreateInstance(serviceName);
MethodInfo mi = wsvcClass.GetType().GetMethod(methodName);
return mi.Invoke(wsvcClass, args);
}
else
{
return null;
}
}
catch (Exception ex)
{
throw ex;
}
}
Now the problem arraize when i have two different client servers. and calling a service from one server to the service deployed on other server. Follwing two kind of error log occurs. Cant find the exact reson for cope up this problem.
System.Net.WebException: The request failed with HTTP status 400: Bad Request.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at MarkUsageHistoryInSTJH.InsertUpdateIssueItemAditionalDetail(String csvBarcode, String csvName, String csvPMGSRN, String csvGLN, String csvMobile, String csvPhone, String csvAddressLine1, String csvAddressLine2, String csvAddressLine3, String csvIsHospital)
and
System.Net.Sockets.SocketException (0x80004005):
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.17.13.7:80
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
Please Carry Out Following Steps :
1) First of all try to access your service by adding reference of it.
It it works fine then we can say that there is no problem related to accessibility and permission.
2) If its not work then there is a problem with connection.
-->So Check Configuration in your service and try to set timeout for your web service.
(http://social.msdn.microsoft.com/Forums/vstudio/en-US/ed89ae3c-e5f8-401b-bcc7-
333579a9f0fe/webservice-client-timeout)
3)Now try after setting the timeout.
it operation completes successfully after above change that means now you can check with your web client method(dymamic calling).
4) If still problem persists then this might be network latency issue. Check the n/w latency between your client and server.
it will helps you.

What in this program

I have been complete my class that will connecting to mysql server.
When I running it I got an error:
Warning: mysql_connect()
[function.mysql-connect]:
php_network_getaddresses: getaddrinfo
failed: This is usually a temporary
error during hostname resolution and
means that the local server did not
receive a response from an
authoritative server. in
C:\wamp\www.php on line 18
Warning: mysql_connect()
[function.mysql-connect]: [2002]
php_network_getaddresses: getaddrinfo
failed: This is usually a (trying to
connect via tcp://test:3306) in
C:\wamp\www.php on line 18
Warning: mysql_connect()
[function.mysql-connect]:
php_network_getaddresses: getaddrinfo
failed: This is usually a temporary
error during hostname resolution and
means that the local server did not
receive a response from an
authoritative server. in
C:\wamp\www.php on line 18 Error
cannnot connect to mysql server
I check my sql server that it had high privileges and dont have a password.
my code:
<?php
class mysql
{
var $user;
var $password;
var $database;
var $host;
function mysql($username, $password, $database, $host)
{
$this->user = $username;
$this->password = $password;
$this->database = $database;
$this->host = $host;
}
function connect()
{
$conn = mysql_connect($this->host, $this->user, $this->password, $this->database)
or die("Error cannnot connect to mysql server");
echo "Connected successfully to Mysql server";
mysql_close($conn);
}
}
$connect = new mysql('127.0.0.1','root','','test');
$connect->connect();
?>
try:
$connect = new mysql('root','','test','127.0.0.1');
I suggest you to defined each property:
var $user;
var $password;
var $database;
var $host;
like these:
private $user;
private $password;
private $database;
private $host;
And create setter and getter methods for each property, an example:
public setUser($user){
$this->user = $user;
}
public getUser(){
return $this->user;
}
Now, I'm sure you are asking yourself: Why? Here there is the answer :-)
bye