Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Sockets server side implementation for NodeJS

Part of this problem might be that there's too much discussion on the client side for me to see wood for the trees.

Anyway, here's what I want to do. I need a platform independent server-side implementation of WebSockets. I'd like it to run in NodeJS.

Now, 99% of what I've found on this topic talks about socket.io. But so far as I can tell, that is not WebSockets, it's a special "extra" protocol in its own right. I need something that works "by the (not-yet) standard". There's a good reason for that, and it's non-negotiable, trust me on that.

So, I tried WebSocket, but that requires (or appears to require both python and, worse, Visual Studio) to run on Windows. I need something that is platform independent and doesn't need special things like this.

I also tried node-websocket-server, but I can't get that to work at all. The example on the main page fails for me. It seems to accept a connection, but the client doesn't see it, neither side gets to send anything, and the client immediately sees the connection as closed. Indeed, all I ever get is a "connection" callback, and then it seems to die. Running in debug mode didn't tell me anything useful, except for some internal error about some object or other not having a flush() method. I half-suspect this is a defunct project?

So, I'm out of ideas. Is it possible to persuade socket.io to work purely by the (non)spec for WebSockets? Is there a way to get node-websocket-server to behave that I've failed to find. Is there a way round the Visual Studio dependency in websocket, or is there some other NodeJS based tool that meets all my requirements?

Oh, one other thing, I'd like the tool to coexist peacefully with "connect" as I'm using that for my regular document serving.

like image 234
Toby Eggitt Avatar asked Dec 18 '12 05:12

Toby Eggitt


People also ask

How do you implement WebSockets in node JS?

All we need to do is call the WebSocket Object with a URI as the parameter. const webSocket = new WebSocket('ws://localhost:443/'); And then we can create an event for the WebSocket to do something when it gets data. That's it we can now receive data from the WebSocket server.

What is WebSocket server in node JS?

What is WebSocket? Websocket is a simple to use, fast and tested WebSocket client and server implementation. The Websocket specification defines an API establishing a connection between a web browser and server. WebSocket is used for creating real-time games, chat applications, displaying stock data, etc.

Is Node JS good for WebSockets?

Node. js can maintain many hundreds of WebSockets connections simultaneously. WebSockets on the server can become complicated as the connection upgrade from HTTP to WebSockets requires handling. This is why developers commonly use a library to manage this for them.

How many WebSockets can Nodejs handle?

The theoretical limit is 65k connections per IP address but the actual limit is often more like 20k, so we use multiple addresses to connect 20k to each (50 * 20k = 1 mil). I then run the web server as root by typing sudo -i followed by ulimit -n 1024000 and then node examples/WebSocket. js (in the uWebSockets.


1 Answers

I had the exact same problem that you're facing at the moment when I tried to use Socket.IO on a different platform without a direct port of the client (and without the motivation to port it myself).

I ended up moving my code to use ws which is a standards based websocket implementation for node without the added sugar from socket.io.

It works extremely well in my case over several different platforms but you would need to rework most of the connection/reconnection code etc.

Website : link

GitHub : link

NPM : npm install ws

like image 186
cillierscharl Avatar answered Sep 25 '22 15:09

cillierscharl