Skip to content

Based on node.js tcp socket of TLV package structure(Node端基于TLV二进制协议格式进行封装的socket工具库,包括粘包断包处理)

License

Notifications You must be signed in to change notification settings

xiaoping6688/node-socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-socket

Based on node.js tcp socket of TLV packet structure (Node端基于TLV二进制协议格式进行封装的socket工具库,包括粘包断包处理)

npm package NPM downloads Percentage of issues still open

其他相关

  • mqtt-socket:Eclipse Paho MQTT Client 封装,实现重连、队列和日志功能等
  • easemob-webim-socket:环信WEBIM实时通信封装 + 客户端模拟器(electron)

Install

$ npm install --save node-socket

Usage

// for client
const socket = require('node-socket').client
socket.connect(options, onConnected, onReceived)

function onReceived (tag, value) {
  switch (tag){
    case TAG_FROM_REGIST_SUCCESS:

      // send message to server
      socket.send(1, { token: '123' })

      break;
    case TAG_FROM_REGIST_FAIL:

      break;
  }
}


// for server
const server = require('node-socket').server

var options = {
  port: 11000,
  timeout: 15000,
  heartbeatTag: 0,
  heartbeatInterval: 7000,
  recreateInterval: 1000
}

server.listen(options, onClientConnected, onClientDisconncted, onClientReceived)

function onClientReceived (tag, value, from) {
  // server.broadcast(tag, value) // all
  server.broadcast(tag, value, null, from) // all, except from
  // server.broadcast(tag, value, clientList, from);
}

//=> @see test_server.js
//=> @see test_client.js

About

Based on node.js tcp socket of TLV package structure(Node端基于TLV二进制协议格式进行封装的socket工具库,包括粘包断包处理)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published