[英]flash xml socket can connect to node.js websocket?
我正在将xml套接字连接到node.js websocket。 首先显示连接消息。 当消息发送到服务器时,显示套接字关闭错误。
导入flash.net.XMLSocket;
var client_socket: XMLSocket = new XMLSocket();
client_socket.connect("localhost",8080);
client_socket.addEventListener(DataEvent.DATA, on_serverData);
client_socket.addEventListener(Event.CONNECT, on_serverConnection);
client_socket.addEventListener(IOErrorEvent.IO_ERROR,IOerror);
client_socket.addEventListener(Event.CLOSE,socketclose);
client_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,socketsecurityerror);
function socketsecurityerror(event:SecurityErrorEvent)
{
trace("socketsecurityerror");
}
function IOerror(event : IOErrorEvent):void
{
trace("IOerror");
}
function socketclose(event : Event):void
{
trace("socketclose");
}
function on_serverConnection(event:Event)
{
trace("connected");
var o :Object= new Object();
o.hello = "initial_start" ;
// client_socket.send(JSON.stringify(o));
}
function on_serverData(event:DataEvent)
{
trace("errorrrrrrrrrr"+event.target.data);
}
可能是问题所在,因为它仅在将数据发送到Websocket时显示连接消息和socketclose错误。
下面的代码是我的websocket服务器。
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ port: 8080 });
wss.on('connection', function connection(ws)
{
ws.on('message', function incoming(message) {
});
ws.on('close', function() {
});
ws.on('error', function() {
});
});
xmlsocket和websocket通信会不会有问题?
谢谢
XMLSocket无法连接到Websocket。
Websocket具有握手和协议(请参阅https://tools.ietf.org/html/rfc6455 ),而XMLSocket仅用于发送和接收XML数据。
如果要在AS3中使用websocket,请尝试使用类似https://github.com/theturtle32/AS3WebSocket的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.