Skip to content

rsp/node-websocket-vs-socket.io

Repository files navigation

Node WebSocket vs. Socket.IO

npm install -g websocket-vs-socket.io
Code Climate Known Vulnerabilities Downloads

Comparing WebSocket and Socket.IO on Node.js with Express.js - example server-side and client-side code to see the basic usage of both WebSocket and Socket.IO in an Express.js app, with info on how to compare the actual network traffic (which is commonly misunderstood by many online sources).

See those Stack Overflow answers where this code was used:

Quick start

Install:

npm i -g websocket-vs-socket.io

Run the server:

websocket-vs-socket.io

Open http://localhost:3001/ in your browser, open developer tools with Shift+Ctrl+I, open the Network tab and reload the page with Ctrl+R to see the network traffic for the WebSocket version.

Open http://localhost:3002/ in your browser, open developer tools with Shift+Ctrl+I, open the Network tab and reload the page with Ctrl+R to see the network traffic for the Socket.IO version.

Uninstall the server:

npm rm -g websocket-vs-socket.io

For more options, see Installation below.

Installation

More options to install the server.

Installing from npm

Installing globally with npm:

# install globally with npm:
npm i -g websocket-vs-socket.io
# run the server:
websocket-vs-socket.io
# uninstall:
npm rm -g websocket-vs-socket.io

Installing locally with npm:

# create a directory:
mkdir ~/websocket-vs-socket.io
cd ~/websocket-vs-socket.io
# install the module:
npm i websocket-vs-socket.io
# run the server:
./node_modules/.bin/websocket-vs-socket.io
# uninstall the module:
npm rm websocket-vs-socket.io
# or remove the entire directory:
rm -rvf ~/websocket-vs-socket.io

Installing from GitHub

You can clone the git repo and install npm dependencies:

# clone the git repo:
git clone git@github.com:rsp/node-websocket-vs-socket.io.git
cd node-websocket-vs-socket.io
# install dependencies:
npm i
# run the server:
./ws-vs-si.js

Alternatively, instead of cloning the repo you can download a ZIP file:

# download and unzip the zip file:
wget https://github.com/rsp/node-websocket-vs-socket.io/archive/master.zip
unzip master.zip
cd node-websocket-vs-socket.io-master
# install dependencies:
npm i
# run the server:
./ws-vs-si.js

Installing from Docker

You can build and run own docker image running from "root" repo folder

docker-compose -f ./docker/docker-compose.yml build
docker-compose -f ./docker/docker-compose.yml up -d

Running

You start the server with either websocket-vs-socket.io (if you installed from npm) or ./ws-vs-si.js (if you installed from the GitHub repo). See Installation above for details.

When the server is running, you can open in your browser:

In Firefox or Chrome, you can open developer tools with Shift+Ctrl+I, open the Network tab and reload the page with Ctrl+R to see the network traffic for both versions.

Issues

For any bug reports or feature requests please post an issue on GitHub.

Author

Rafał Pocztarski - https://github.com/rsp

Contributors

Thanks

Special thanks to:

for comments and suggestions.

License

MIT License (Expat). See LICENSE.md for details.

About

Comparing WebSocket and Socket.IO on Node.js with Express.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •