|
-
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.
Last edited by vamp4l; 07-02-2009 at 07:59 AM.
-
still can't figure this out..bump
-
Sorry, I don't have any idea why it wouldn't respond except when prodded. But I did want to tell you that the latest versions of FlashDevelop support native trace. You don't have to use FlashConnect.trace anymore.
-
yea i was so stumped why all of my traces weren't working yesterday then i saw the flashconnect.trace function had changed.
so just doing a trace("test") will work now?
-
Yeah, it should. I use one of the recent builds, and plain trace has been working for a while.
-
whats happening is my onData event fires when I send data across the socket, but it doesnt fire on receive...is this proper behavior? is there some other way to set up a receive data method?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|