Simple demo of a node-based websocket client and server using ws.
Our server sends out a timestamp once a second and our client simply prints out any messages it receives.
Install ws
:
npm install -g ws
Running the server:
# server.coffee
websocket server created -> ws://localhost:8081
use CTRL-C to quit
connection open
connection closed
^C
Running the client:
# client.coffee
connected (use CTRL+C to quit)
"2013-12-17T18:03:56.943Z"
"2013-12-17T18:03:57.945Z"
"2013-12-17T18:03:58.946Z"
"2013-12-17T18:03:59.947Z"
^C
Connecting to the server with wscat
:
# wscat -c ws://localhost:8081
connected (press CTRL+C to quit)
< "2013-12-17T18:11:11.124Z"
< "2013-12-17T18:11:12.127Z"
< "2013-12-17T18:11:13.128Z"
< "2013-12-17T18:11:14.129Z"
> ^C