当用户连接时,它应使用唯一的用户名(例如电子邮件)向服务器发送消息。
一对用户名和套接字应存储在这样的对象中:
var users = { 'userA@example.com': [socket object], 'userB@example.com': [socket object], 'userC@example.com': [socket object]}在客户端上,使用以下数据向服务器发送对象:
{ to:[the other receiver's username as a string], from:[the person who sent the message as string], message:[the message to be sent as string]}在服务器上,侦听消息。收到消息后,将数据发送到接收方。
users[data.to].emit('receivedMessage', data)在客户端上,侦听来自称为“ receivedMessage”的服务器的发射,通过读取数据,您可以处理其来源和发送的消息。



