XMLSocket receive data help
I am having newbie problems with sockets. Flash sends data to my php server script fine, and my telnet client(s) all get updated. When I make an entry into a telnet client, all of the other clients update immediately as expected. In Flash however, the only time I receive data is when I press a key within flash. Example:
Press 'a' within Flash, flash traces a, telnet outputs a
Press b in telnet, telnet outputs b, nothing within flash
Press c in Flash, flash traces b, c, telnet traces c
Here is my updated code:
package {
import flash.display.Sprite;
import flash.net.*;
import flash.events.*;
import org.flashdevelop.utils.FlashConnect; //for trace
public class Thisisatest2 extends Sprite
{
private var mySocket:XMLSocket;
public function Thisisatest2()
{
mySocket = new XMLSocket();
mySocket.addEventListener(Event.CONNECT, onConnect);
mySocket.addEventListener(Event.CLOSE, onDisconnect);
mySocket.addEventListener(DataEvent.DATA, onData);
stage.addEventListener(KeyboardEvent.KEY_DOWN, sendMsg);
mySocket.connect("192.168.2.4", 8999);
}
private function onConnect(event:Event):void{
FlashConnect.trace("<b>Server connection established!</b>");
}
private function onDisconnect(event:Event):void{
FlashConnect.trace("<b>Server connection lost</b>");
}
private function onData(event:Event):void {
FlashConnect.trace("data: " + event.data);
}
private function sendMsg(event:KeyboardEvent):void
{
mySocket.send(event.keyCode);
}
}
}
I guess this is more of an issue of how to set up Flash to listen for events on the socket
Any ideas appreciated, thanks.