如何在 flash、XMLSocket 中拆分数据包
您好,我相信我的闪存客户端正在丢失服务器发送的一些数据包,因为一些数据包连接在一起,因此我相信它会丢弃它们。
这是我在闪存中的 packetHandler
private var xmlsock:XMLSocket;
this.xmlsock = new XMLSocket();
xmlsock.connect("127.0.0.1", 1234);
this.xmlsock.addEventListener(DataEvent.DATA, this.packetHandler);
public function packetHandler(event:DataEvent):void {
var packet:String = event.data;
var args:Array = packet.split(":");
if(args.length <= 0) return;
switch(args[0]) {
case 'w': //waiting
ExternalInterface.call("waiting");
break;
case 'u': //user count
if(args.length >= 2)
ExternalInterface.call("userCount", args[1]);
break;
//... etc handlers ...
}
}
我嗅探到的服务器发送的可能数据包。
u:105.w。又名 (75 3A 31 30 35 00 77 00)
所以等待的数据包永远不会进来。
我将如何修复这个错误..我正在使用 XMLSocket
Hello I believe my flash client is losing some packets the server sends, because some packets get joined together hence I believe it drops them.
Here is my packetHandler in flash
private var xmlsock:XMLSocket;
this.xmlsock = new XMLSocket();
xmlsock.connect("127.0.0.1", 1234);
this.xmlsock.addEventListener(DataEvent.DATA, this.packetHandler);
public function packetHandler(event:DataEvent):void {
var packet:String = event.data;
var args:Array = packet.split(":");
if(args.length <= 0) return;
switch(args[0]) {
case 'w': //waiting
ExternalInterface.call("waiting");
break;
case 'u': //user count
if(args.length >= 2)
ExternalInterface.call("userCount", args[1]);
break;
//... etc handlers ...
}
}
A possible packet I sniffed sent by the server was.
u:105.w. aka (75 3A 31 30 35 00 77 00)
so the waiting packet never came in.
How would i go about fixing this bug.. I am using XMLSocket
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
K 解决了如果有人需要帮助,结果证明你可以这样做
var packet:Array = data.split("\x00");
K solved if anyone needs help with this turns out you can just do this
var packets:Array = data.split("\x00");
请改用
flash.net.Socket
。Use a
flash.net.Socket
instead.