debanka
debanka

Reputation: 277

Maximum size of characters that can be sent through TCP socket

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?

Upvotes: 1

Views: 4024

Answers (2)

user207421
user207421

Reputation: 310869

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.

Upvotes: 0

dau_sama
dau_sama

Reputation: 4357

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.

Upvotes: 2

Related Questions