Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http'),
- io = require('socket.io'),
- people = {},
- server = http.createServer(function(request, response) {
- response.writeHeader(200, {"Content-Type": "text"});
- response.write("Good job.");
- response.end();
- }).listen(8080);
- var socket = io.listen(server);
- socket.on("connection", function (client) {
- client.on("join", function(name){
- people[client.id] = name;
- client.emit("update", "You have connected to the server.");
- socket.sockets.emit("update", name + " has joined the server.")
- socket.sockets.emit("update-people", people);
- console.log("join");
- });
- client.on("send", function(msg){
- socket.sockets.emit("chat", people[client.id], msg);
- console.log("send");
- });
- client.on("disconnect", function(){
- socket.sockets.emit("update", people[client.id] + " has left the server.");
- delete people[client.id];
- socket.sockets.emit("update-people", people);
- console.log("disconnect");
- });
- });
- console.log("Running");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement