I wrote the following code for chat client to client(client1 to server server to client2) but I am getting an error:
Missing error handler on socket
.
T
You've binded Your app to 3000-th port, and set socket.io to work with http module that listens on 3000.
So You've to change on clientside this:
var socket = io.connect('http://localhost');
to this:
var socket = io.connect('http://localhost:3000');
or just:
var socket = io.connect();
also from Your code:
users[data.uid]=data.uid;
users[data.uname] =data.uname;
I don't see any logic here :) Why not to keep it like:
users[data.uid] = {uid: data.uid, uname: data.uname}
sockets[socket.id] = socket;
if(!users[data.uid].sockets) {
users[data.uid].sockets = [];
}
users[data.uid].sockets.push(socket);