Implement Simple Websocket with Node.js

It’s been almost two months since I wrote anything in here and before moving forward in topics I will try to add something more with the web socket technology.

As I have written in the last topic here I ‘d like to present a very simple way to create Websocket server. This was implemented with Java EE7.

This time I wanted to try to use Node.js and to my surprise things got much easier.

The only thing I had to do (apart from installing Node.js) was to install the module ws with the command:

npm install ws

That’s it! Now the following code is a sample of doing the whole thing:

… and in case you haven’t read the previous post here is the html5 client to test it:

Leave a Reply

Your email address will not be published. Required fields are marked *