0

I am trying to write python server that communicates with a Particle Photon micro-controller. The micro-controller should send updates when the status has changed, and also accept commands from the server to run a calibration or other actions.

There are raw sockets in Python that act more low-level (How Do I Use Raw Socket in Python?), however, I am not currently using one of those.

In my python server code, I open the sockets as a SOCK_STREAM:

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Now, I want to make sure that my packages arrive uncorrupted on both ends, and was considering adding a checksum. However, TCP already has a checksum in its packages, so do I still need to build yet another checksum into my protocol?

Given that I am communicating between a C-style lower level language and a Python, should I be using RAW_Sockets instead?

All communication is on a LAN over Wifi.

avgJoe
  • 832
  • 7
  • 24

1 Answers1

1

However, TCP already has a checksum in its packages, so do I still need to build yet another checksum into my protocol?

Depends on what kind of guarantee you need. If the comparably weak guarantees of the TCP checksum are sufficient for you then you don't need to add another one. If not you somehow need to add some stronger checksum method to the protocol you use between your application and the micro-controller.

Given that I am communicating between a C-style lower level language and a Python, should I be using RAW_Sockets instead?

Raw sockets don't add any value in your use case but just make everything significantly more complex. These are used if lots of control is needed outside of the actual application payload. But these are not the right way to add some stronger checksum - this should be done instead inside your application protocol and thus manifest in the data payload. And even without raw sockets some control outside of the payload can be achieved with various setsockopt.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172