简体   繁体   English

Raspberry Pi Python应用程序和Node.js socketio通信

[英]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. 我的要求是将socketio与nodejs服务器通信到运行本地Python应用程序的Raspberry Pi。 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. 我可以在Google上找到与网络应用进行通信的方式,但是有满足上述要求的与Python本地应用进行通信的任何方式。

It's unclear exactly which part you need help with. 目前尚不清楚您需要帮助的部分。 To make a socket.io connection work, you do the following: 要使socket.io连接正常工作,请执行以下操作:

  1. Run a socket.io server on one of your two computers. 在两台计算机之一上运行socket.io服务器。 Make sure it is listening on a known port (it can share a port with a web server if desired). 确保它正在侦听已知端口(如果需要,它可以与Web服务器共享端口)。

  2. On the other computer, get a socket.io client library and use that to make a socket.io connection to the other computer. 在另一台计算机上,获取socket.io客户端库,并使用该库建立与另一台计算机的socket.io连接。

  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. node.js和python都具有Socket.io客户端和服务器库,因此您可以为任何一种系统类型使用任何一种库。

The important things to understand are that you must have a socket.io server up and running. 要了解的重要事项是必须启动并运行socket.io服务器。 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. 例如,您可以在node.js上设置一个socket.io服务器。 Then, use a socket.io client library for python to make a socket.io connection to the node.js server. 然后,使用python的socket.io客户端库建立与node.js服务器的socket.io连接。 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. 然后,一旦连接建立并开始运行,您就可以自由地从任一端向另一端发送消息,并且如果有的话,消息处理程序会侦听那些特定的消息,它们将被另一端接收。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM