Fawad Khalil
Fawad Khalil

Reputation: 367

Raspberry Pi python app and nodejs socketio communication

My requirement is to communicate socketio with nodejs server to Raspberry Pi running a local Python app. Please help me. I can find ways of communication with web app on google but is there any way to communicate with Python local app with above mentioned requirements.

Upvotes: 0

Views: 952

Answers (1)

jfriend00
jfriend00

Reputation: 707328

It's unclear exactly which part you need help with. To make a socket.io connection work, you do the following:

  1. Run a socket.io server on one of your two computers. Make sure it is listening on a known port (it can share a port with a web server if desired).

  2. On the other computer, get a socket.io client library and use that to make a socket.io connection to the other computer.

  3. Register message handlers on both computers for whatever custom messages you intend to send each way and write the code to process those incoming messages.

  4. Write the code to send messages to the other computer at the appropriate time.

Socket.io client and server libraries exist for both node.js and python so you can either type of library for either type of system.

The important things to understand are that you must have a socket.io server up and running. The other endpoint then must connect to that server. Once the connection is up and running, you can then send message from either end to the other end.

For example, you could set up a socket.io server on node.js. Then, use a socket.io client library for python to make a socket.io connection to the node.js server. Then, once the connection is up and running, you are free to send messages from either end to the other and, if you have, message handlers listening for those specific messages, they will be received by the other end.

Upvotes: 1

Related Questions