Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
EvanSaunders6-Apr-10 3:03
EvanSaunders6-Apr-10 3:03 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
Rod Kemp6-Apr-10 3:14
Rod Kemp6-Apr-10 3:14 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
EvanSaunders6-Apr-10 3:27
EvanSaunders6-Apr-10 3:27 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
Rod Kemp6-Apr-10 4:32
Rod Kemp6-Apr-10 4:32 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
EvanSaunders6-Apr-10 20:30
EvanSaunders6-Apr-10 20:30 
AnswerRe: Sending Large Files in C# using TCP Client/Server Pin
Luc Pattyn6-Apr-10 2:31
sitebuilderLuc Pattyn6-Apr-10 2:31 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
EvanSaunders6-Apr-10 2:41
EvanSaunders6-Apr-10 2:41 
AnswerRe: Sending Large Files in C# using TCP Client/Server Pin
Luc Pattyn6-Apr-10 3:16
sitebuilderLuc Pattyn6-Apr-10 3:16 
Hi,

I have looked into your different approaches, and here are some comments:

1.
you should avoid reading all file data into memory at once; that is quite acceptable for small sizes, it becomes a bottleneck on large files though. Streams are the fundamental solution to this, as they offer a way to process data while it comes along, without ever needing all of it at once.

So your attempts #1 and #2 are out.

2.
you should also avoid base64 encoding, unless your communication channel is only working properly with printable ASCII characters; example: some serial communications (I mean over RS232C) only work properly with simple text, arbitrary byte values might upset the serial driver and/or modems involved in the communication.

base64 is both calculation intensive and it expands the data, as it uses one character to encode 6 bits (which means 3 bytes become 4 characters), something you want to avoid especially when the amount of data is large.

3.
and finally you should avoid copying all the data as your transmitter #2 does. It is expensive and does not bring you anything.

4.
your receiver #1 does not fit your transmitter #1 as it relies on a receiving buffer of fixed size (4096) whereas the sender uses a single, possibly huge, buffer. Now base64 will append up to 2 fill characters while encoding, and the decoder will not understand the data as it is chopped into 4096-byte packets, lacking the padding characters that should go with that.

5.
your third approach looks most promising, however you should keep it simple. There is no need to calculate the number of packets in advance, it is just adding complexity (and working against the streaming idea, as you are relying on total size, which implies all the data has to be present somewhere).
Simply make a loop reading some data (from the file) and sending that data (to the network), until there is no more data, at which point you close the output stream. Should work like a charm.
Your receiver #3 looks fine.

Smile | :)

GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
EvanSaunders6-Apr-10 3:30
EvanSaunders6-Apr-10 3:30 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
Luc Pattyn6-Apr-10 3:36
sitebuilderLuc Pattyn6-Apr-10 3:36 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
EvanSaunders6-Apr-10 3:54
EvanSaunders6-Apr-10 3:54 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
Luc Pattyn6-Apr-10 4:05
sitebuilderLuc Pattyn6-Apr-10 4:05 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
EvanSaunders6-Apr-10 4:14
EvanSaunders6-Apr-10 4:14 
GeneralRe: Sending Large Files in C# using TCP Client/Server Pin
hussien ahmmed20-Sep-11 16:53
hussien ahmmed20-Sep-11 16:53 
QuestionHow to create an installer for Excel Plug In Pin
Ashish_Sood5-Apr-10 22:58
Ashish_Sood5-Apr-10 22:58 
AnswerRe: How to create an installer for Excel Plug In Pin
Eddy Vluggen5-Apr-10 23:15
professionalEddy Vluggen5-Apr-10 23:15 
GeneralRe: How to create an installer for Excel Plug In Pin
Ashish_Sood6-Apr-10 2:21
Ashish_Sood6-Apr-10 2:21 
GeneralRe: How to create an installer for Excel Plug In Pin
Eddy Vluggen6-Apr-10 3:01
professionalEddy Vluggen6-Apr-10 3:01 
QuestionHow to retrieve last application startup time Pin
Rikq5-Apr-10 22:17
Rikq5-Apr-10 22:17 
AnswerRe: How to retrieve last application startup time Pin
Mycroft Holmes5-Apr-10 22:36
professionalMycroft Holmes5-Apr-10 22:36 
AnswerRe: How to retrieve last application startup time Pin
Luc Pattyn6-Apr-10 2:30
sitebuilderLuc Pattyn6-Apr-10 2:30 
AnswerRe: How to retrieve last application startup time Pin
PIEBALDconsult6-Apr-10 4:37
mvePIEBALDconsult6-Apr-10 4:37 
QuestionError While Large File Uploading Pin
sjs4u5-Apr-10 21:08
sjs4u5-Apr-10 21:08 
QuestionStore and retrieve list of structures Pin
Reza Shojaee5-Apr-10 19:44
Reza Shojaee5-Apr-10 19:44 
AnswerRe: Store and retrieve list of structures Pin
Eddy Vluggen5-Apr-10 22:13
professionalEddy Vluggen5-Apr-10 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.