简体   繁体   English

TCP客户端Flash AS3

[英]TCP Client Flash AS3

I've been trying to get flash to receive TCP messages from a small Serial to IP converter I have. 我一直在尝试让闪存从我拥有的小型Serial to IP转换器接收TCP消息。 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 really 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. 从闪存中,我尝试使用Socket和XML套接字,但是我不确定自己在做什么,我设法建立了连接,但它似乎没有输出数据,也没有在数据触发时触发事件。收到。 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. Flash需要通过套接字连接到任何服务器的权限,它需要在端口843上寻求权限。Adobe拥有一个很好的有关限制的文档 ,以及一些解决该问题的示例代码。 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. 如果您无法直接访问要连接的服务器,则可能需要使用代理服务器进行探索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM