Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My develop environment is a multi cores Linux server and I want to make the data transfer from net more quickly so I want to use several cores to do the socket part , but I don not know how to do multi threads socket programing in server or client . So I want to get some help from other people.
Posted
Comments
Sergey Alexandrovich Kryukov 13-Feb-11 20:56pm    
What is your question? Where is your effort?
Nish Nishant 13-Feb-11 21:51pm    
Updated my answer.

1 solution

Okay, using multiple threads to take advantage of the multiple cores on the server will not help speed up your download since that purely depends on your bandwidth. But if your idea is to make parallel connections to a server and download multiple parts of the same file, then that may help improve the speed if the server restricts download speeds on a single connection. This trick is used by several HTTP and FTP downloading tools to work around speed restrictions enforced by download servers.

But if that's your game plan, you will not be using the same socket across multiple threads since that would be pointless. Instead you'd have each thread use its own socket to fetch a specific part of the file to download. And then you'd have one main thread that'd manage these multiple downloads and sync up the downloaded parts into one single file. In fact depending on your scenario, you may even begin processing the data from the multiple downloads (although I can't say how useful that will be for you since I don't really know anything about your app).

[Edit]
~~~~~~~~

Assuming you are using HTTP to download a file as multiple parts, you need to use a Range header. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35[^] for more info on that. Of course if your server uses a custom protocol then you need to use a different approach that will work with that protocol.
 
Share this answer
 
v5
Comments
Sergey Alexandrovich Kryukov 13-Feb-11 21:38pm    
OP commented:

Thank you for your answer . But I also want to know how to transfer a file in several sockets ?
Nish Nishant 13-Feb-11 21:51pm    
Updated my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900