C++ socket与Flex as3通信的沙盒问题解决

地址:

http://www.cnblogs.com/sevenyuan/archive/2012/06/20/2556494.html

可新开一个socket服务端监听843端口,专门用于处理as3发来的沙盒请求。处理后再把连接关闭即可。

// 额外的一个问题

AS3读取C++socket发送来的数据,提示 遇到文件尾错误 。

//如出现Error: Error #2030: 遇到文件尾错误,请用:str=socket.readUTFBytes(socket.bytesAvailable);

 

Some of this errors are thrown if the proper listener is not added.

Are you listening for asyncError and ioError events from your netconnection?

If not, just give it a try.

额,终于弄明白了,并不是服务器的问题,也不是换行符的问题,是TCP/IP通信协议的问题,貌似JAVA的直接读取不会出现这个问题,上面的JAVA服务器端每次接受到的客户端的数据都是正确的,AS3有这个问题,是每次读的时候没有读全字节流,要检验数据包的完整性的,当包长度>=服务器封包的长度时,再读取的话就不会出现上面的问题了。
例如把 if (_socket.bytesAvailable >= 4)
            {
                cmd = _socket.readUnsignedInt();
                ondeal(cmd);
            }
改成if (_socket.bytesAvailable >= 20)
            {
                cmd = _socket.readUnsignedInt();
                ondeal(cmd);
            }
客户端就会读出正确的数据
原文地址:https://www.cnblogs.com/sylar-liang/p/4646100.html