0

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# ?

2

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Or if on .Net 4.0 could probably just use the FileStream.CopyTo(Stream) overload and let the framework handle the chunking.
...you can't copy stream to stream until you construct a NetworkStream around the socket: msdn.microsoft.com/en-us/library/cd8fz0y3.aspx

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.