Question for the Socket qurus

Anything and everything related to network programming

Question for the Socket qurus

Postby Cpp_Noob » Sun Jun 13, 2010 12:44 am

heres my question, i hope i can write it as clear as i can.


lets say we have a Client and a Server setup using Asynchronous sockets. The Client trys to send 2 files simultaneously with 2 different threads.
Each thread calls send() and tranfers a piece of 7000 bytes of the file until all file data have been send (using a loop)

Now since TCP is a stream-oriented , the 7000 bytes i send could not end up been recieved as one piece but rather as multiple small chunks or even been merged with the next piece.

Now here comes the real question:
Since i got 2 threads from the same socket sending 2 different files simulatiusly to the Server, and the TCP stream does not guarantee to recieve what you send as one piece, but more likely on small chunks , could the chunks from the 2 different file get mixed together?
Does the Server recieve the chunks from the packages i send in order or arbitrary?

i hope i made the question clear enough ;)
User avatar
Cpp_Noob
Regular
 
Posts: 42
Joined: Thu Jun 18, 2009 12:05 pm

Re: Question for the Socket qurus

Postby joemc » Tue Jun 15, 2010 12:04 pm

i call from send() or should complete before the next call to send. the only problem would be if send() does not send the full buffer and returns less than the full amount. Using smaller sizes should help. Winsock1 had many more problems than Winsock2 in this regard. which version are you using? I would probably put a mutex on calls to send() but i doubt it is required.

i would just send a byte or even bit to distinguish which channel it is for, and the length. I am not sure why you would want to use two different threads to send files over the same socket :) but it should work fine. Why not two sockets? Either way look at the "OSCAR PROTOCOL" and you will see the header is well suited for something like this. I would drop the order bytes because it would not be necessary with TCP.
joemc
Veteren
 
Posts: 127
Joined: Fri Jul 10, 2009 1:29 pm

Re: Question for the Socket qurus

Postby Cpp_Noob » Tue Jun 22, 2010 10:09 am

thanks i will have a look on "OSCAR PROTOCOL" :)
User avatar
Cpp_Noob
Regular
 
Posts: 42
Joined: Thu Jun 18, 2009 12:05 pm


Return to Winsock And Networking

Who is online

Users browsing this forum: No registered users and 1 guest

cron