Click here to Skip to main content
15,900,110 members
Home / Discussions / C#
   

C#

 
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 
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 
Is this better:

Server:
System.IO.FileStream inFile = new System.IO.FileStream(theCompressedFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] binaryData = new Byte[inFile.Length];
                
long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
inFile.Close();
int bytesSent = 0;

while (bytesSent < binaryData.Length)
{
  serverStream.Write(binaryData, 0, 1024);
  bytesSent += 1024;
}   
             
serverStream.Flush();
client.Close(); //**note this


Client:
FileStream fs = new FileStream(theFileName, FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);

byte[] theFile = new byte[1024];
while (clientStream.Read(theFile, 0, 1024) > 0)
{
   bw.Write(theFile);
   theFile = new byte[1024];
}

fs.Flush();
fs.Close();
bw.Flush();
bw.Close();


** When I remove the line of code indicated, the file is sent as is and can be opened on client side. However, because I removed this, there is no end to the stream (I think) and the client keeps waiting.
But when this line is there, the file is not sent exactly as is for some reason (it is always slightly larger - sometimes 1kb) and the file is corrupted and won't open.

Can you please help?
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 
Questionhow to get the row index value in datagridview Pin
crisjala5-Apr-10 17:27
crisjala5-Apr-10 17:27 
AnswerRe: how to get the row index value in datagridview Pin
Reza Shojaee5-Apr-10 20:00
Reza Shojaee5-Apr-10 20:00 
Questionpass an object by value. Pin
prasadbuddhika5-Apr-10 17:08
prasadbuddhika5-Apr-10 17:08 

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.