Avoid “destroying non-socket.io upgrade” error

浪尽此生 提交于 2019-11-30 18:06:21

问题


I am trying to make a socket.io based server but whenever I connect by client to it using dojo, it shows me this error:

    debug - destroying non-socket.io upgrade

Here's my server code

var express = require("express");
var io = require("socket.io");
server= express.createServer();
var server_socket = io.listen(server);

server_socket.sockets.on("connection",function(socket)
{
    console.log("connection established");
    socket.emit("message", message);
});

server.listen(8080);

And here's my client code

require(["dojox/socket"], function (socket)
{
    var args, ws = typeof WebSocket != "undefined";
    var _socket = dojox.socket(args = {
        url: ws ? "ws://localhost:8080/" : "http://localhost:8080",
        headers:{
        "Content-Type":"application/x-www-urlencoded"
         },
        transport: function(args, message){
          args.content = message; // use URL-encoding to send the message
                                  // instead of a raw body
          dojo.xhrPost(args);
         }
    }); 
    websocket = dojox.socket.Reconnect(_socket);
    websocket.on("message",function(data)
    {
       console.log(data);
    });
});

Please help me.


回答1:


Socket.io is both a server and client side library for node.js. I'm guessing Dojo's websocket client is not directly compatible with the socket.io server. I would suggest just using the socket.io client for connections, otherwise you will probably have to modify Dojo's websocket library which will probably be difficult.




回答2:


Setting "destroy upgrade" to false on socketio server configuration will fix this problem.



来源:https://stackoverflow.com/questions/10049587/avoid-destroying-non-socket-io-upgrade-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!