0.1.6 • Published 9 years ago

node-websocket v0.1.6

Weekly downloads
10
License
MIT
Repository
github
Last release
9 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

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago