Answer the question
In order to leave comments, you need to log in
How to correctly read data from tcp-socket?
Hello! How to get around the following error:
Developing a client-server application
Under certain conditions, the client first sends the server a header with the size of the next message and other information, and then sends the data to be written to the database
Somehow the server is coded, in fact, there are too many pitfalls
Now , for example, for a long time I could not understand why the code stopped working, and I just commented out print(data) on the server between sock.recv(title) and sock.recv(size), because when I commented out the line, I received a message like : "size{message}" instead of just size. But if you uncomment print, the server gets some delay and reads messages separately
Already too often I struggle with the problem that the server reads more or less data than it should, so I decided to turn here for help with a solution. What is the best way to build interaction?
Answer the question
In order to leave comments, you need to log in
It is enough to write working code.
It's also helpful to read the documentation.
Using my experience as a telepath, I can say that you probably haven't looked at the sock.recv documentation. But what you are sending and how is generally a mystery, you would have given the client and server code, and at the same time a description of the communication protocol. You can also look for examples on github.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question