Node.js client to server with socket.io
Socket.io is usually employed by browser apps communicating with a Node.js server application. It is however possible to create a client in Node.js if you need to call the same server application. It is also possible for the server to return values by calling a function that the client passes to it.
You’ll need to install
npm as shown below. Additionally, we also use
express for serving static HTTP content.
This is how a client connection can be established. The namespace
ns is used for communicating with the server. Client emits the event
call with parameter
p1, and a function parameter that receives a response code and additional data. Remember to export global node_modules folder in
NODE_PATH before running the script with
npm -g list | head shows the path to node_modules.
This is how a server can serve the…
View original post 8 more words