article

A sample to transfer binary through winsock at very very high speed (Meet industrial standard)

Email
Submitted on: 1/26/2015 4:00:00 AM
By: Kenny Lai, Lai Ho Wa (from psc cd)  
Level: Advanced
User Rating: By 34 Users
Compatibility: VB 6.0
Views: 5389
 
     

Have you ever used Flashget, NetAnt, or Download Accelerator?

They can download very very fast because they SPLIT up files into many parts to download together.

This program demonstrate how to use this technique to send all binary files(exe, jpg, zip....) through winsock without corruption.



This article has accompanying files

 
				

Have you ever used Flashget, NetAnt, or Download Accelerator?

They can download very very fast because they SPLIT up files into many parts to download together.

This program demonstrate how to use this technique to send all binary files(exe, jpg, zip....) through winsock without corruption.


As you know, the Microsoft Winsock Control only allow two type of data to be transfer: One is string and one is Byte Array. In this tutorial, I will use byte array to send file via winsock of course, as byte array is the only data type that can store a huge binary file correctly without corruption.

The traditional method to sent binary files is just use the senddata method to send the whole byte array of a huge file. You can imagine a 2MB file is stored in a single byte array of count of 2000000!!!!!!! It is so large that if you sent it directly through one line, your machine will go down deadly. Also, the speed is extremely low, about 60-90 KBps. (All the speed here is measured Local-to-Local only, which is the maximum speed that can reach.)

In this program, I will send files through chunks, of course. A chunk is a group of defined number of bytes, my default is 4096 bytes per chunk(I have done many experiments to find out the optimum size of each chunk). This means one winsock will send the byte array for many times, each time with one chunk. This can balance the use of CPU and memory with a great increase of performance, about 400-600KBps.

But it still doesn't perform well. In my test, if I send a 12MB VB5CCE Zip file, the speed decrease to 63KBps shortly.

IS IT ENOUGH FOR INDUSTRIAL STANDARD? OF COURSE NOT! It just utilized one winsock only. In my program, I will split up the binary file into many chunks of each 4096bytes, AND I will group 128 chunks into ONE PACKAGE.

The most cool stuff is that I open ONE Winsock for ONE Package, and Each use a separate port! In the screen shot you can see, I send a 13MB file, and there's 26 package. That means I use 26 Winsock to send the file together. The speed is awsome, 1808KBps, that is 14.125Mbps!!!!!!!

The method to split file and rebuild file is well commented. Please see it if you like and test it.


I worked for a long time to work out the structure for binary byte array and send through winsock, but if I just send the entire file through one command, it is too slowly, unreasonable even in Local-to-Local. In fact, my program is not trying to fool the server, but it uses the idea of multi-threading. Later, I will develop a binary-transfer OCX with multi-thread support, one package one thread. The method of spliting up file is to use multiple port and winsock to send file(As you may know, a winsock has is own speed limit that is quite slow). Sending through chunks and package can REDUCE the memory usage and INCREASE CPU load, i.e. to draw the CPU performance.

IN GENERAL, THE PURPOSE OF THIS PROGRAM is to increase the MAXIMUM capacity of transfer irrespective of the bandwidth(the bottle-neck of internet transfer). But technology with advance, and the bandwidth will rise(How can you imagine if both machines have T3 connections but the server only transfer the file at a 40KBps limits? That what I want to say and my purpose of this program.

PLEASE VOTE AND GIVE COMMENTS!

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 12 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

10/20/2016 7:40:59 AMgalih

Hi, i'd try to send a pdf file using this program, but the transferred file was corrupted, can't open correctly.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.