首页 > 解决方案 > send data with categories from client to a server using python

问题描述

I have an embedded system that monitors many sensors (GPS, Motor Speed, Temperature..)

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 ".

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.

Is there a way to do it in TCP or using any library or framework?

Thank you

标签: pythonsocketstcpembedded

解决方案


我能想到三种方法

  1. 将消息类型放在标题中(可能在消息大小旁边)
  2. 为每种消息类型使用不同的套接字(丑陋而复杂但有效)
  3. 使用某种 pub-sub 例如 Kafka、ZeroMQ 或 RabbitMQ 来传达主题

推荐阅读