Setting Up Socket.io

In notebook:
FrontEndMasters Real-Time Web with Node.js
Created at:
2015-10-14
Updated:
2015-10-14
Tags:
JavaScript libraries
3:52:39 - 4:02:27 Setting Up Socket.io Socket.io is a Node module that enables real-time bidirectional communication in the browser. It's built on top of the native HTML5 Web Socket API. Kyle shows how to install and set up Socket.io with the current Node application.an inital http request for a websocket
response an upgrade protocol to persistent websocket connection

you want to be using SSL

socket.io is an extension to websockets: handshakes (that the server received your message)
for his example, at the time of the workshop he suggests to use:
​npm install socket.io@0.9.16​ 

​var io = require("socket.io").listen(http_serv);

(where ​var http_serv = http.createServer(handleHTTP).listen(port, host);​ ) 
see note:Node as a Webserver )

note: the ​var io​ should point to the socket library and not the module, hence we have to call ​.listen(http_serv);​ when assigning the module to ​io​ 
it will hijack the httpServer and listen for websockets requests 
the handleHTTP​ will continue to function

then in the client: 
​<script src="/socket.io/socket.io.js"></script>​  the above hijacking will automatically handle the request for socket.io.js file
then you get a global called ​io from socket.io