Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Websockets
- socket = io.listen(server);
- socket.on('connection', function(client){
- console.log(('Client connected: ' + client.sessionId).green.bold);
- client.send('Hello ' + client.sessionId);
- client.on('message', function(message) {
- if (message.text == "hello"){
- // ADD A CLIENT
- servers[client.sessionId] = {'counterid' : message.counterid};
- console.log(("\tclient " + client.sessionId + " wants info for counter " + message.counterid).yellow);
- // this is dangerous if we de-couple ids from positions in the array.
- providers[message.counterid - 1].addClient();
- }
- });
- client.on('disconnect', function() {
- try {
- // REMOVE THE CLIENTS
- // this is dangerous if we de-couple ids from positions in the array.
- providers[servers[client.sessionId].counterid - 1].removeClient();
- console.log(('Client ' + client.sessionId + ' disconnected. - Stopping Processing for ' + providers[servers[client.sessionId].counterid - 1].host).cyan.bold);
- delete servers[client.sessionId];
- } catch (err) {
- console.log((sys.inspect(err)).red);
- }
- });
- })
- socket.on('error', function(client) {
- console.log("error!")
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement