0.1.6 • Published 10 years ago

node-websocket v0.1.6

Weekly downloads
10
License
MIT
Repository
github
Last release
10 years ago

websocket

parse socket buffer, add event emitter and cookie id

download & install

// in package.json
"dependencies": {
  "node-websocket": ">=0.0.1"
}
$ npm install

config & run

// in your nodeserver file
var ws = require('node-websocket').init;
// bind events
ws.on('connection', function(socket) {
  console.log(socket.id); // ID in cookie,key: socketId
  ws.on('join', function(data) {
    //send message
    socket.send('yes! it will send to frontend');
  });
});

// You should emit server's close event and delete socket object when frontend exit
ws.on('close', function(socketId) {
  console.log('close ' + socketId);
  delete sockets[socketId];
});

// you need start server in the end
ws.start(8000);

emit in frondend

// you need creat socket object first
socket.send(JSON.stringify({
  event: 'join',
  data: {
    room: room
  }
}));

all arguments & events & methods

  • Server.prototype.start(port)

  • Server 'connection' event, emit when connect success, create socket object in callback

  • Server 'close' event, emit when a socket ended, return socketId.

  • Server.prototype.on(eventName, callback);

  • Server.prototype.emit(eventName, data);

  • socket.id, ID in cookie,key: socketId

  • Socket.prototype.send(data);

  • Socket.prototype.close(data);

bug && suggestion?

Tell Me Please~

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago