XMLSocket events not received
I'm trying to get a simple ActionScript 3 class to connect to a custom Java Server. The server receives the connection, but no events are triggered on the ActionScript side. I am serving a policy file and loading explicitly on the side of the ActionScriptThe simplest code to reproduce, it is as follows:
=====
Java code:
=====
import java. IO;
java.net import. *;
SimpleServer class
{
Public Shared Sub main (String [] args)
{
System.out.println ("> > starting SimpleServer");
Try
{
int ch;
System.out.println ("opening server socket to port 8080");
Socket ServerSocket = new ServerSocket (8080);
System.out.println ("Waiting for connection on port 8080");
Plug incoming = socket.accept ();
System.out.println ("connection accepted. Pending text");
BufferedReader readerIn = new BufferedReader (new InputStreamReader (incoming.getInputStream ()));
PrintStream print = new PrintStream (incoming.getOutputStream ());
System.out.println ("read :");
While ((ch = readerIn.read ()) > 0)
System.out.println ("read :");
While ((ch = readerIn.read ()) > 0)
{
System.out.Print ((Char) ch);
}
System.out.println("\nDone");
System.out.println ("exit strategy");
printOut.println ("<?") XML version=\"1.0\"? " > \r\n <! ("" "DOCTYPE cross-domain-policy SYSTEM------" http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd------"> \r\n < cross-domain-policy > < ow-access-of all area =------" *------' course =------"false\" to-ports =------' 8080, 8081\ "/ > < / cross-domain-policy > \0");
System.out.println ("close connections");
incoming. Close();
Socket.Close ();
System.out.println ("taken to port 8080 closed");
System.out.println ("opening server socket to port 8081");
Socket = new ServerSocket (8081);
System.out.println ("Waiting for connection");
incoming = socket.accept ();
System.out.println ("Waiting for connection");
incoming = socket.accept ();
System.out.println ("accepted connection to port 8081");
System.out.println ("isConnected:" + incoming.isConnected ());
readerIn = new BufferedReader (new InputStreamReader (incoming.getInputStream ()));
Print = new PrintStream (incoming.getOutputStream ());
System.out.println ("sending < Hello / >");
printOut.println ("< Hello / > \0");
System.out.println ("smell");
System.out.println ("isConnected:" + incoming.isConnected ());
System.out.println ("read :");
While ((ch = readerIn.read ()) > 0)
{
System.out.Print ((Char) ch);
}
System.out.println("\nDone");
System.out.println ("isConnected:" + incoming.isConnected ());
System.out.println ("sending < Hello / >");
printOut.println ("< Hello / > \0");
System.out.println ("smell");
System.out.println ("isConnected:" + incoming.isConnected ());
System.out.println ("close connections");
incoming. Close();
Socket.Close ();
System.out.println ("taken to port 8080 closed");
}
catch (System.Exception e)
{
System.out.println (e);
}
}
}
=====
ActionScript code:
=====
package
{
import flash.display.Sprite;
SerializableAttribute public class SockTest extends Sprite
{
import flash.net.XMLSocket;
import flash.system.Security;
import flash.events. *;
import flash.utils.Timer;
public void SockTest()
{
trace ("type of Sandbox:" + Security.sandboxType);
trace ("loading policy file");
Security.loadPolicyFile ("xmlsocket://127.0.0.1:8080"); ")
trace ("done calling loadPolicyFile");
var: timer = new Timer (1, 5000);
timer.addEventListener ("timer", timerHandler);
Timer.Start ();
}
private void timerHandler(event:TimerEvent):void
{
trace ("XMLSocket creation");
var xmlSocket:XMLSocket = new XMLSocket();
trace ("Calling connect");
xmlSocket.connect ("127.0.0.1", 8081);
trace ("done connect call");
trace ("adding event listeners');
xmlSocket.addEventListener (Event.CONNECT, connectHandler);
xmlSocket.addEventListener (Event.CLOSE, closeHandler);
xmlSocket.addEventListener (DataEvent.DATA, dataHandler);
xmlSocket.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);
xmlSocket.addEventListener (SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
trace ("adding event listeners through");
trace ("willTrigger (Event.Connect)?:"+ xmlSocket.willTrigger (Event.CONNECT) ");
trace ("xmlSocket.Connected =" + xmlSocket.Connected);
xmlSocket.send (new XML code ("< Hello / >"));
trace ("done send");
}
public void connectHandler(event:Event):void
{
trace ("connectHandler:" + event);
}
private void closeHandler(event:Event):void
{
trace ("closeHandler:" + event);
}
private void dataHandler(event:DataEvent):void
{
trace ("dataHandler:" + event);
}
private void ioErrorHandler(event:IOErrorEvent):void
{
trace ("ioErrorHandler:" + event);
}
private void securityErrorHandler(event:SecurityErrorEvent):void
{
trace ("securityErrorHandler:" + event);
}
}
}
=====
ActionScript compiled using
mxmlc-use-network = true SockTest.as
=====
Result of Java side:
=====
> > from SimpleServer
Opening of socket server on port 8080
Waiting for connection on port 8080
Accepted connection. Pending text
Read:
< policy-file-request / >
Fact
Political output
Close connections
Taken closed to port 8080
Opening of socket server to port 8081
Waiting for connection
Connection accepted to port 8081
isConnected: true
Sending of < Hello / >
Envoy
isConnected: true
Read:
Fact
isConnected: true
Sending of < Hello / >
Envoy
isConnected: true
Close connections
Taken closed to port 8080
=====
Output trace for the ActionScript side: [from the debug version of the flash player version 9,0,31,0 stand-alone on Linux]
=====
Type of sandbox: localWithNetwork
Loading policy file
Fact call loadPolicyFile
Creating XMLSocket
Call connect
Call connect
Add event listeners
Result of adding event listeners
willTrigger (Event.CONNECT)? : true
xmlSocket.connected = false
Because of the sending
=====
As you can see, no event is fired. I know that the policy file has effect because if I try to connect to any other port, I get a security exception, but here again the SecurityErrorEvent is not triggered. In addition, the data sent from the server not fire either all DataEvent.
How can I get the events to trigger?
Thank you
Vincent
I got it finally works but I do not understand why it makes a difference.
I did the
var xmlSocket:XMLSocket
an instance variable instead of declare inside the timerHandler method.
I do not understand why is this necessary. The timer works fine (timerHandler is invoked) even when it's a local variable.
Vincent
Tags: Flex
Similar Questions
-
Change of calendar events not received the 8900
I created an application using the example at this link:
I have change BlackBerryEventList to BlackBerryPIMList so he could work on the 8300 (v4.2.2.170).
Tested also on a storm (v4.7.0.75) and it reported successfully add/set day/remove events in the calendar.
Some events are called on the 8900 (v4.6.1.114).
Anyone has any ideas what could be wrong?
Thank you
Note that there may be more than one calendar on a BlackBerry smartphone. Each calendar database has its own PIMList. You can view these by opening the calendar and selecting Options from the menu. The method PIM.openPIMList (int pimListType, int mode) returns the default calendar. You can use the PIM.listPIMLists (int pimListType) method to get a list of all calendars and then a specific target by using the method PIM.openPIMList (String name, int pimListType, int mode).
This support has been added in version 4.6.0 BlackBerry terminal software.
-
PC is Windows XP. The server is Windows 2000. I have administrative rights on both machines.
On getting PC security event log do message "local computer, maybe not the files of the necessary registry information or message DLL to display messages from a remote computer" for all entries. System and application logs do not receive messages
Hi carmol,.
Your question of Windows is more complex than what is generally answered in the Microsoft Answers forums. It is better suited to the audience on TechNet forum.
Please post your question in the Sub forum. Link: http://social.technet.microsoft.com/Forums/en-us/winserverManagement/threads
With regard to:
Samhrutha G S - Microsoft technical support.
Visit our Microsoft answers feedback Forum and let us know what you think.
-
Hi I buy chips 4900 rupees today. For the game teen patti app unlimited
The cut on my account but not received money chips game please help me as soon as POSSIBLE.
Thanks and greetings
Ashu KhatriContact the manufacturer of the App or iTunes and ask them about it.
-
Office of Mac OS X 10.7
I am able to send emails but not receive.
Hi susanna denholm!
I see that you are unable to receive e-mails in your Mac Mail application. I know the importance of being able to receive by email in the Mail application, and I'm happy to help you. Please try all the advice in the following support article:
If you cannot send or receive e-mail on your Mac.
Thank you for using communities of Apple Support.
See you soon!
-
iMessage problem does not receive past messages
I recently left the country for a month had to remove my sim card to avoid any roaming charges. When I came back I put my card back in and realized that I had not received one of my last iMessages or missed calls a month. Even during my trip, I had wifi but without the sim card I have still not got any iMessages. I called apple about the problem and my phone carrier and have updated my phone to the latest version, but nothing has worked for me. Basically, I'm trying to just go back one month messages and missed calls that may be important for me. Any thoughts?
You will get back iMessages old. They are not be stored anyhere for you to recover from. In regards to missed calls, I'm not aware of your rack system record any kind of list of missed calls, but the carrier must be the one to answer that question. Unless the caller has left a voicemail, calls are gone.
-
I am not receiving texts on my iMac
I have not received the texts of the iPhone for 3 weeks. My ID Apple is not the password. How can I change the message password?
Hello
Text messages are managed by the provider of mobile phone network
That's why you don't get them on your mac.
Only imessage to apple phones appears on your mac.
See you soon
Brian
-
Have not received e-mail on info @ address for repetitive emails started 8/1 at 13:04. I have active malware, anti-virus programs. Don't have any experience with the realization of resets on my computer. The e-mails come through on my iPhone so trying to figure out what the problem might be with my computer.
Use a web browser to connect to the mail server and delete repeated messages. Looks like it was damaged on the server and make a mess of everything.
-
Purchased from bingolive90 app and items not received. What are my next steps?
Hello
Follow the instructions here:
If you do not see your in-app purchases - Apple Support
If you still need assistance, please contact iTunes Support:
-
can not connect to firfox to ask a question requested e mail reminder not received
I am signing in mozilla support for a question and answer to another, but it won't let me connect, I asked for an e-mail reminder of my username 5 times had no e-mail, has also asked the link reset my password but still not received any e-mail. I tried to register my details but no luck
Well, your entry went thru and you were able to log in here.
What is your question or support problem?
-
I'm impossible to connect, and you do not receive the password email when I ask.
I'm trying to connect with the stored user name and password, but they do not work. I tried new password sent by e-mail, 5 or 6 times in the last 24 hours, but I never received an email.
Connect to what?
The extent of the not received the email, have you looked into the Spam folder?
-
My registration has been confirmed, I posted my question, I filled in the details and expect an email to confirm my email address. He never came. What can I do on my question if I do not receive your email.
If you were registered you could not post here. Click on your name in the upper left corner of one of your posts to see your questions and messages.
This link will take you to the same place. -
I understand the accounts settings before 2010 to reset password, but it's difficult if you can not receive the link to get the discount to zero fact. Please can we get this support. I made several request for the link, at least 6 in the last two weeks!
Firefox account?
-
I have not received the email so that I can install the new Firefox.
I downloaded the new version, but he says I'll get an e-mail so that I can install it then. I have not received this e-mail.
You need not register to install Firefox. Newsletter registration is optional.
For 29 of Firefox, you can use the integrated update. Try:
Help > about Firefox
Firefox must immediately begin to download the update.
Does it work?
-
Changed computers from xp to windows 8. Received emails, but now nothing, lost all messages on the new computer. can send but not receive. must use xp computer to check email
Check the settings of Thunderbird yoru Server
Maybe you are looking for
-
Did I lose progress in blocked games?
I have an iPad 2 Air runs the latest version of the software, not jail broken. It is however controlled admin and some applications have been blocked accidentally like YouTube, Google, clash of Clans, Clash Royal etc. I played both of these games for
-
I've been hacked and I want to know if firefox can help you
I got hacked to access facebook from a wifi site... the motel where I went down... is possible to have firefox to get rid of the intruder? Or how can I get rid of him? If the owner of the wifi changes the password to get on will this help?
-
When I visit a Web site that requires SSL I displays the message "this connection is untrusted". Any Web site that I visit, it's always exactly the same message and the same SSL certificate that she is no longer valid for www.thawte.com support.Mozil
-
Parts of a web page are colored in a pungent pink color as buttons, links, pop up windows and a few others.
-
channel and time stamps contatenation
My task is to create a VI that takes 50 readings of temperature inside a loop, once every seconds 0.25 and plots each on a chart. He also converts the replays to a string and then concatenates this string with a tab character, a timestamp, and an end