Solved

Compressing data to be sent through Winsock

Posted on 2004-08-09
3
456 Views
Last Modified: 2013-11-13
Hello,

I have a client/server application where the server sends a file to the client application as a byte stream using the Winsock control. I would like to compress the stream (using zlib or something similar) in the server, then decompress it in the client.

I've found an example using zlib that compress the whole file at once, but since some files are very large, I want to compress each data chunk that is sent on the fly. Is there a way to accomplish that?

Thanks in advance,

Ricardo.
0
Comment
Question by:ricardog2
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 11761175
Compression performance gets potentially better the larger the file is, because of the possible data pattern that can be compressed that way. If you want to compress small chunks, the results may even become negative, as compression also starts with some overhead.
If you have a really large file (say > 50MB), then you might start splitting the file into chunks of 10MB, zip them and send send the zipped chunks...
To split the files, you have to binary read the files and binary write the chunks... Don't forget to send to the client how many and how big the chunks are, best would also be to send some hash code of the chunks and the total to check the several results...

CHeers
0
 
LVL 1

Author Comment

by:ricardog2
ID: 11802097
I can calculate the number of compressed chunks that will be sent before the transfer begins, but how would I know their size? Unless I split the whole file at once (which I don't want to do because that would require too much disk space), I can only notify the client of the next chunk size during the transfer, but then I would have a problem to separate the file data from the chunk size data.

Any ideas?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 11803944
Yes, have 2 connections open to the client, 1 for the data transfer, and 1 for the information/command transfer.
That's how I have managed to do such kind of things...
Cheers
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now