【问题标题】:flash xml socket can connect to node.js websocket?flash xml套接字可以连接到node.js websocket?
【发布时间】: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通信会不会有问题?

谢谢

【问题讨论】:

标签: node.js sockets flash


【解决方案1】:

XMLSocket 无法连接到 Websocket。

Websockets 有握手和协议(参见https://www.rfc-editor.org/rfc/rfc6455),而 XMLSocket 仅用于发送和接收 XML 数据。

如果你想在 AS3 中使用 websockets,试试https://github.com/theturtle32/AS3WebSocket

【讨论】:

    猜你喜欢
    • 2014-05-28
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 2011-04-07
    • 2012-03-03
    相关资源
    最近更新 更多