• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 [email protected]: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.

More Repositories

1

scripts

Random shell scripts for different tasks
Shell
110
star
2

node-static-http-servers

Examples of serving static files with HTTP using Node.js
JavaScript
35
star
3

gh-pages-no-extension

GitHub Pages test with no .html extentson
HTML
21
star
4

deno-clipboard

The clipboard copy/paste API for Deno
TypeScript
16
star
5

travis-hello-modern-cpp

Simple Travis example using C++ with modern compilers
Shell
14
star
6

node-caught

A function to avoid UnhandledPromiseRejectionWarning and PromiseRejectionHandledWarning
JavaScript
10
star
7

node-tco

Tail call optimization in Node
JavaScript
9
star
8

deno-dirname

Node-style __dirname and __filename polyfill for Deno
TypeScript
8
star
9

node-express-static-example

Example for Stack Overflow
HTML
7
star
10

docker-experiments

See what tools are available by default in Docker images and other Docker experiments
Shell
6
star
11

node-live-color

Changing website background color live with Node/Express/Socket.io
JavaScript
5
star
12

node-is-not-letter

JavaScript
5
star
13

pg-scott

Classical Scott database (EMP, DEPT, SALGRADE) for PostgreSQL
PLpgSQL
5
star
14

ts-no-new

TypeScript constructors without 'new' keyword - several attempts by @rsp
TypeScript
5
star
15

node-socket.io-remote

An example of remotely controlled web page with Node and Socket.IO
HTML
4
star
16

t.ts

A t.ts standard for adding TypeScript type definitions to JavaScript modules alternative to d.ts files
TypeScript
4
star
17

nw1

Node Workshop - Lesson 1
3
star
18

warsawjs-workshop-22-unit-converter

Unit Converter Project for WarsawJS Workshop 22 Group 1 by @rsp
JavaScript
3
star
19

node-hapi-helpers

Define hapi.js routes with less code
JavaScript
2
star
20

deno-wabt

A Deno port of https://github.com/AssemblyScript/wabt.js which is a JS port of https://github.com/WebAssembly/wabt
JavaScript
2
star
21

git-experiments

Some experiments with git commits, hashes and collisions
Shell
2
star
22

node-promise-monofill

A module that exports native Promise. Always.
JavaScript
2
star
23

node-nested-project-structure-example

Node.js nested module structure example
JavaScript
1
star
24

nodekeeper-4-test

Test repo for nodekeeper-4
1
star
25

docker-pg-scott

PostgreSQL with a classical Scott database (EMP, DEPT, SALGRADE) in Docker
PLpgSQL
1
star
26

warsawjs-workshop-31-calendar

warsawjs-workshop-31-calendar
JavaScript
1
star
27

node-isoso

isoso - ISO 8601 Simple Operations - CLI date manipulation
JavaScript
1
star
28

rsp

README for @rsp
1
star
29

cmi

cmi
CSS
1
star
30

node-the-global-object

The global object in Node or in the browser
JavaScript
1
star
31

travis-hello-cpp

Simple Travis example using C++
Shell
1
star
32

scripting-wars

A competition between scripting languages
1
star
33

warsawjs-workshop-23-unit-converter

Unit Converter Project for WarsawJS Workshop 23 Group 1 by @rsp
JavaScript
1
star
34

node-immoment

Immutable Moment - Like Moment.js but without surprises
JavaScript
1
star
35

node-rsp

Radically Simplifed Promises - call methods on values in the future
JavaScript
1
star
36

ppj

random Java examples
Java
1
star
37

warsawjs-workshop-23-warmup

WarsawJS Workshop #23 - Warmup Project
JavaScript
1
star
38

nodekeeper-20

Makes Greenkeeper re-run your tests on new Node.js 20.x releases
1
star
39

deno-rand

Random utilities for getting random numbers in Deno
TypeScript
1
star
40

nw2

Node Workshop - Lesson 2
JavaScript
1
star
41

node-filt

filt is for simple filters: node -e 'require("filt")(line => line.toUpperCase())'
JavaScript
1
star
42

ajax-cdn-speed-test

a speed test for free CDNs hosting JavaScript libraries
Shell
1
star