A
A
Arthur Samurai2020-08-21 09:56:17
Python
Arthur Samurai, 2020-08-21 09:56:17

How to mark TCP traffic in Python?

Tell me which way to dig, there is a client and a server on sockets, how to mark each message or file so that the server understands where the message begins and ends. The data is read using recv(bytes). I can’t find the info, and as an option, for example, before each sending of data, send a start and end message at the end, and on the server read in a loop until I find the word end? Maybe this is not the right option, xs. If anyone has something to share, I will be grateful)
PS Packing in json does not work, problems with encodings have not yet been sorted out (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
javedimka, 2020-08-21
@javedimka

The simplest option - the first byte - the length of the message. Further, as it is more convenient, if you want, do recv(1) + recv(how much it turned out there), i.e. read one message at a time. Or recv (as much as you like) and parse the line with code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question