将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通信会出现问题吗?
由于
答案 0 :(得分:0)
XMLSocket无法连接到Websocket。
Websockets具有握手和协议(请参阅https://tools.ietf.org/html/rfc6455),而XMLSocket仅用于发送和接收XML数据。
如果您想在AS3中使用websockets,请尝试使用https://github.com/theturtle32/AS3WebSocket
之类的内容