Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var http = require('http');
- var server = http.createServer(app);
- var io = require('socket.io').listen(server);
- io.enable('browser client minification');
- io.enable('browser client etag');
- io.enable('browser client gzip');
- io.set('log level', 1);
- io.set('transports', ['websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']);
- server.listen(8080, '192.241.129.20');
- app.get('/', function(req, res){
- console.log("REQUEST\t/\t" + req.addr);
- res.sendfile(__dirname + '/index.html');
- });
- io.sockets.on('connection', function(socket){
- socket.name = "User " + Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
- socket.emit("System", "You are " + socket.name);
- socket.broadcast(socket.name, "connected.");
- console.log("JOIN\t" + socket.name);
- socket.on('message', function(message){
- if(socket.channel){
- console.log("MESSAGE\t" + socket.name + "\t" + message);
- sendToChannel(socket.channel, ["message", moment().unix(), socket.user.uuid, socket.user.name, message]);
- }else
- socket.emit("notLoggedIn");
- });
- socket.on('disconnect', function(){
- console.log("LEAVE\t" + socket.name);
- socket.broadcast(socket.name, "disconnected.");
- });
- });
- console.log("Started.");
Advertisement
Add Comment
Please, Sign In to add comment