just wanted to ask what should be the limit of bytes when data is being sent back and forth from server and client, with the great feed back i have go i understand this a bit more, so now the question is what are the size of segmented bytes sent over a connection?
So if i set a buffer size of 3072 bytes to be sent to the server from the client and the same when sending data from server to client, how are these bytes segmented? and what would be the maximum number of bytes that is sent over a connection so that the bytes dont get segmented?
TCP do not guarantee that the number of bytes sent with one send command in the client will be the same number of bytes received in the server with one receive command. TCP is stream based with means that it treats the connection as a stream of bytes and not a stream of messages.
Sending this (two sends):
Can be received as:
or.
or any other combination.
Hence you need to be able to detect when one message end and the next begins. The two most common ways is to either use a message header containing the length or a suffix (like a line feed) to detect the end of a message.
Update
TCP should not be used for audio streaming imho. The reason is that TCP guarantees to deliver all sent packets. Hence if TCP detects that a packet didnt arrive it will block all queued packets until the failed one arrives.
When streaming audio it’s not important that all packets arrive, one lost packet wont affect the sound too much. It’s better to get a little audio loss than to let the audio stream stop completely because the network protocols tries to deliver all packets.