.net版Socketio4net类库和java版socket.io-java-client类库 连接socket.io 1.4版本都不行,网上大多是socket.io 0.9版本的,socket.io 更新之后就不支持了。本人已研究

成功连接socket.io 1.4版本的方法,例子采用C#。

  一、socket.io 几个重要要文件

   1、node_modules\socket.io\node_modules\engine.io\node_modules\engine.io-parser\lib\index.js  

var packets = exports.packets = {
    open:     0    // non-ws
  , close:    1    // non-ws
  , ping:     2
  , pong:     3
  , message:  4
  , upgrade:  5
  , noop:     6
};

    这几个是定义消息类型的 websocket连接的时候在open事件里需要发送一个send("5[\"simple\",{\"name\":\"simple\"}]"); 类型为5的消息。

    

exports.decodePacket = function (data, binaryType, utf8decode) {
  // String data
   console.log('解析数据'+data);
  if (typeof data == 'string' || data === undefined) {
    if (data.charAt(0) == 'b') {
      return exports.decodeBase64Packet(data.substr(1), binaryType);
    }

    var type = data.charAt(0);
     
    if (utf8decode) {
      try {
        data = utf8.decode(data);
      } catch (e) {
        return err;
      }
    }
    console.log('解析数据3:'+type);
    if (Number(type) != type || !packetslist[type]) {
      return err;
    }

    if (data.length > 1) {
      return { type: packetslist[type], data: data.substring(1) };
    } else {
      return { type: packetslist[type] };
    }
  }

  // Binary data
  if (binaryType === 'arraybuffer') {
    var type = data[0];
    var intArray = new Uint8Array(data.length - 1);
    for (var i = 1; i < data.length; i++) {
      intArray[i - 1] = data[i];
    }
    return { type: packetslist[type], data: intArray.buffer };
  }
  var type = data[0];
  return { type: packetslist[type], data: data.slice(1) };
};
View Code

相关文章:

  • 2021-07-31
  • 2022-01-14
  • 2021-11-26
  • 2021-12-26
  • 2022-12-23
  • 2021-08-21
  • 2021-11-21
  • 2021-10-12
猜你喜欢
  • 2021-09-05
  • 2022-12-23
  • 2021-06-15
  • 2021-10-28
  • 2021-11-19
  • 2021-12-18
  • 2022-12-23
相关资源
相似解决方案