且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WebSocket 服务器的***实践是什么?

更新时间:2021-12-04 08:50:15

只需为每个房间滚动您自己的 broadcast 版本,您会保留该房间中的用户列表,如果有人发送进入/发送到该房间的消息只需将其发送给房间中的所有用户,然后根据您的协议,您可以排除消息的原始发件人.

Just roll your own version of the broadcast for each room you keep a list of users in that room, and if someone sends a message in/to that room just send it to all the users in the room, depending on your protocol you can then exclude the original sender of the message.

无论如何,您都有每个房间的用户列表,因此您只需将连接作为属性添加到用户对象即可.

You have a list of users for each room anyway, so you can just add the connection as a property to the user object.

但请记住,由于最近发现"了当前 WebSocket 规范的安全问题,Opera 和 Mozilla 都禁用了对 WebSocket 的支持,直到发布新版本.因此,WebSockets 需要更多时间才能广泛使用,并且服务器需要更改为新版本.

But keep in mind that due to recently "discovered" security problem with the current WebSocket specification, both Opera and Mozilla have disabled support for WebSocket until a new version has been issued. So it will take some more time for WebSockets to have widespread availability and server needs to change to with the new version.

详情见:
http://hacks.mozilla.org/2010/12/websockets-disabled-in-firefox-4/
http://blog.pusherapp.com/2010/12/9/it-s-not-websockets-it-s-your-broken-proxy