Home > Uncategorized > Node.js client to server with socket.io

Node.js client to server with socket.io

delog

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 socket.io and socket.io-client using 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

Newer versions of node, don’t require NODE_PATH to be set to the global module path used by npm i -g.

This is how…

View original post 13 more words

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: