用socket.io连接python3

时间:2014-11-12 07:22:58

标签: node.js sockets python-3.x websocket socket.io

我尝试将socket.io与python3连接但我有一些错误 我试试这个: python3:

conexion =http.client.HTTPConnection('192.168.1.64','3000')
    conexion.request('POST','/socket.io/1/')
    respuesta=conexion.getresponse()
    print(respuesta.read()) #response b'{"code":0,"message":"Transport unknown"}'
    hskey=respuesta.read().split(":")[0]
_ws = websocket.WebSocket(
                    'ws://192.168.1.64:3000/socket.io/1/websocket/'+hskey,

错误:

 hskey=respuesta.read().split(":")[0]
TypeError: Type str doesn't support the buffer API

服务器:

io.set('origins', '*:*');
io.set("transports", ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'polling']);
io.set("heartbeat interval", 2); 
//io.set('transports', ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'polling']);
//io.set('transports', ["websocket", "polling"]);
io.set('authorization', function (handshakeData, accept) {

  if (handshakeData.headers.cookie) {

    handshakeData.cookie = require('express/node_modules/cookie').parse(handshakeData.headers.cookie);

    handshakeData.sessionID = require('express/node_modules/connect/lib/utils').parseSignedCookie(handshakeData.cookie['express.sid'], 'secret');

    if (handshakeData.cookie['express.sid'] == handshakeData.sessionID) {
      return accept('Cookie is invalid.', false);
    }

  } else {
    return accept('No cookie transmitted.', false);
  } 

  accept(null, true);
});

python 3的socket.io库不起作用

我从这里复制代码: Socket.io connection url?

socket.io版本1.2

0 个答案:

没有答案