Reputation: 10400
I have a client-server communication in Python. If I'm sending 10MB data from the server to the client in one package can the client handle this big data in one package? What if the client is reading the data after 1minute. For example, I establish a connection and sending the 10MB message to the client, but the client is capable to receive the message only after 1 minute ore more. How big is the TCP buffer? Is it possible to lose data (buffer overflow). Will it hang the server?
time.sleep(60)
self.request.recv( 20480 )
Upvotes: 0
Views: 711
Reputation: 22089
TCP is stream oriented, not packet oriented, so it makes no sense to talk about "one package" in TCP. While the data will in fact be sent as IP packets further down the network stack, the TCP layer will guarantee that you can not discern how the data is split into packets and reassembled on the receiving side.
The TCP buffer size is not specified in a standard, but if the server does not read from the socket when the buffer on the server side is full, the client will stop sending. In other words, TCP does flow control. In this scenario, you might actually hang the client.
What you should do is to continually send chunks of some manageable size (say 8k) from the client, and continually read on the server. The data should be buffered on the server side in your program if you need it. As I said, TCP does not deal in packets.
Upvotes: 3