【发布时间】:2016-11-09 20:16:17
【问题描述】:
正在将 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通信会不会有问题?
谢谢
【问题讨论】:
-
stackoverflow.com/questions/10542577/… 这似乎是一个类似的问题。但不知道如何解决我的问题。