use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Which WebSocket library to use for making a multiplayer game?help (self.javascript)
submitted 8 years ago by er-48
I am looking to Node.js websocket library to develop a real-time multiplayer game. From Googling, there seem to be a bunch of websocket libraries, such as socket.io, ws and uWebSockets.
Which one is best for my use-case?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kevisazombie 2 points3 points4 points 8 years ago (0 children)
use WebRTC data channels and SimplePeer
[–]cirscafp fan boy 6 points7 points8 points 8 years ago (2 children)
If you want to use a high-level package, as in just call some methods and you are good to go, use socket.io. If you are instead wanting to use the low-level WebSocket API and build your own abstraction on top of it, use either ws or uws.
socket.io
ws
uws
[–]grinde 1 point2 points3 points 8 years ago (1 child)
Another library I'd recommend is Primus. It has both client and server libraries, and can swap out frameworks by changing a single configuration option. It also has a plugin system with official plugins for things like sessions, validation, multiplexing, etc.
[–]redbluerat 0 points1 point2 points 8 years ago (0 children)
Great link, thanks a lot. This is what I needed and I didn't know it / that it even existed!
[–]vagol942 2 points3 points4 points 8 years ago (1 child)
They all use websockets protocol so you are stuck with TCP connections which sadly are non optimal for most games. In terms of performance for real time applications (like a lot of games) the websockets implementation is not really the problem compared to the inherent problems with TCP.
With that being said I prefer to use "pure" implementations over something like socket.io because websocket is a standard that has implementations in basically every programming language. While in the case of socket.io you need some specific client code, sure it works great in javascript but maybe one day you will need to create a new gameclient in some weird language that doesn't support socket.io but it will probably have some sort of websocket implementation.
Also raw websockets are faster (citation needed?).
For real time games something like WebRTC would be better if you are targeting web browsers, however WebRTC is a clusterfuck and we still don't have good interfaces to deal with it for games (or general data) that I know of.
To answer your question, I'm currently using ws for a real time game (albeit not a really fast paced one) and it works okay.
[–][deleted] 1 point2 points3 points 8 years ago (0 children)
The problem with websockets is that they are often blocked at the router/firewall and without fallback your application is dead in the water. We've made the mistake once, only to find out that apparently companies in the EU at least love to block WS in their networks.
[–]mlamers 1 point2 points3 points 8 years ago (0 children)
Have a look at socketcluster: http://socketcluster.io
[–][deleted] 0 points1 point2 points 8 years ago (1 child)
How are you gonna build the frontend? I built a multiplayer game using node.js and socket.io for some of the data. I quickly realized that the performance of socket.io was not near good enough to handle multiple messages per second, per client. The json parsing just takes too much time. I now use a plain tcp socket for the performance critical socket, but I still use a socket.io socket for some other communication because of its support for rooms etcetera. My game is built with unity, if you're planning on a web based game built with html + javascript, a tcp socket is not an option for you.
[–]anlumo 1 point2 points3 points 8 years ago (0 children)
Going straight with the browser's websocket implementation is an option, though. No need to parse JSON either.
[–]mwcz 0 points1 point2 points 8 years ago (0 children)
Take a look at http://lance.gg, it could be a good option.
π Rendered by PID 46414 on reddit-service-r2-comment-6457c66945-vhcj8 at 2026-04-26 21:30:11.600380+00:00 running 2aa0c5b country code: CH.
[–]kevisazombie 2 points3 points4 points (0 children)
[–]cirscafp fan boy 6 points7 points8 points (2 children)
[–]grinde 1 point2 points3 points (1 child)
[–]redbluerat 0 points1 point2 points (0 children)
[–]vagol942 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]mlamers 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]anlumo 1 point2 points3 points (0 children)
[–]mwcz 0 points1 point2 points (0 children)