简体   繁体   English

使用python将带有类别的数据从客户端发送到服务器

[英]send data with categories from client to a server using python

I have an embedded system that monitors many sensors (GPS, Motor Speed, Temperature..)我有一个嵌入式系统,可以监控许多传感器(GPS、电机速度、温度……)

I set up a client-server using sockets in python and I can send from the client(the embedded system) to the server(a Laptop) a string message like " Hello from client ".我在 python 中使用套接字设置了一个客户端 - 服务器,我可以从客户端(嵌入式系统)向服务器(笔记本电脑)发送一个字符串消息,比如“来自客户端的你好”。

But for me it would be great to send data with predifined categories so the server knows the type of the message.但对我来说,发送带有预定义类别的数据会很棒,这样服务器就知道消息的类型。 Upon reception the server knows it has recieved for example a GPS coordinate or motor speed.收到后,服务器知道它已收到例如 GPS 坐标或电机速度。

Is there a way to do it in TCP or using any library or framework?有没有办法在 TCP 中或使用任何库或框架来做到这一点?

Thank you谢谢

I can think of three ways我能想到三种方法

  1. Put the message kind in the header (next to the message size, probably)将消息类型放在标题中(可能在消息大小旁边)
  2. Use different sockets for each message kind (ugly and complicated but works)为每种消息类型使用不同的套接字(丑陋而复杂但有效)
  3. Use some sort of pub-sub eg Kafka, ZeroMQ or RabbitMQ to convey topics使用某种发布订阅,例如 Kafka、ZeroMQ 或 RabbitMQ 来传达主题

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

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