TCP Client Flash AS3
I've been trying to get flash to receive TCP messages from a small Serial to IP converter I have. Using some other software I can see the messages coming through so I know that bit it working. From flash I've tried using a Socket and an XML socket but I'm not rea开发者_StackOverflowlly sure what I'm doing, I've managed to get a connection but it doesn't seem to output the data, or trigger events when data is received. Not sure I'm going the right way about this, any help would be appreciated.
Thanks
The following is the code I used to get this working. Thanks for the help guys.
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.Socket;
var RFIDSocket:Socket = new Socket(RFIDSocketIP,RFIDSocketPort);
RFIDSocket.addEventListener(ProgressEvent.SOCKET_DATA, socketData);
private function socketData(e:ProgressEvent):void {
var rawData:String = RFIDSocket.readUTFBytes(RFIDSocket.bytesAvailable);
var RFIDData:String = RFIDData.substring(1,11);
if(debugMode){
MonsterDebugger.trace(this, RFIDData);
}
RFIDSocket.flush();
}
My guess is you are probably hitting security restrictions. Flash needs permission to connect to any server through a socket, it looks for permission on port 843. Adobe has a pretty good document on the restrictions, as well as some sample code for getting around it. If you don't have direct access over the server you are trying to connect to, you may need to explore using a proxy server.
精彩评论