WebSockets and Node JS
Many examples/tutorials are based on NodeJS.
Node JS on MSYS2
nodejs
/npm
MSYS2 packages are outdated:
https://stackoverflow.com/questions/46473196/installing-nodejs-and-npm-on-msys2
Workaround: Download for MS Windows from https://nodejs.org/en/:
Add to path, or enable the following line to C:\msys64\msys2.ini
:
MSYS2_PATH_TYPE=inherit
Close any open MSYS2 windows, start a new shell and check:
$ which node
/c/Program Files/nodejs/node
$ which npm
/c/Program Files/nodejs/npm
Example 1
Start server:
node server01.js
Check from client:
node server02.js
Lighweight alternative to websockets: SSE (Server-Sent Events)
https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events
Example:
https://github.com/mdn/dom-examples/tree/master/server-sent-events
Links
- https://www.oreilly.com/library/view/websocket/9781449369262/ch01.html O'Reilly
- https://www.piesocket.com/blog/nodejs-websocket/ Tutorial
- https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers MDN - Writing WebSocket servers
- https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications MDN - Writing WebSocket client applications
- https://riptutorial.com/node-js/example/14908/-hello-world---with-socket-messages- with Express minimal web framework
- https://github.com/phusion/passenger-nodejs-websocket-demo With Phusion Passenger
- https://en.wikipedia.org/wiki/WebSocket Wikipedia
- https://ably.com/blog/websockets-vs-sse
- https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events