Maximum size of characters that can be sent through TCP socket

3.8k views Asked by At

I have a c++ client that sends a large string (Minimum size 10 KB) to a Java server application after a certain interval. During that interval the c++ application accumulates huge bytes of data and sends it completely to server.The server also receives it at one shot.

I want to keep the size of the string variable less than string::max_size at all times. Once the string's size approaches the limit I will then send that string to server and clear the string and only then move on collecting the remaining data.

and if the string can hold the complete data , will the entire data be transferred from client to server without fail.(Assuming no connection reset or any other such problem arises.)

Can somebody tell me If this is the way to proceed?

2

There are 2 answers

3
dau_sama On BEST ANSWER

the client wouldn't know how big is the string, and it wouldn't know when to stop listening and start processing the received string.

You need to send the size of the string as an int, then send the data over. When the server has received all the data, it will know that the string has been received correctly.

2
user207421 On

Yes, but I suggest you send the data as you acquire it, rather than adding latency and wasting space buffering it all up. TCP will take care of it.