i was looking for a way to send file through Socket on C# but i was not lucky to find sample code or ... as you know in Socket we should send an array of byte and array length is MaxInt and a file is larger than MaxInt. is there a way to send a FileStream through windows Socket on C# ?
1 Answer
Read the file in chunks (for example 64KB at once). Send each chuck individually. That allows you to stream arbitrarily large files.
Starting with .NET 4.0 you can use Stream.CopyTo(Stream) to make this a one-liner.
2 Comments
user7116
Or if on .Net 4.0 could probably just use the
FileStream.CopyTo(Stream) overload and let the framework handle the chunking.spender
...you can't copy stream to stream until you construct a NetworkStream around the socket: msdn.microsoft.com/en-us/library/cd8fz0y3.aspx