On the server side, you can use TcpListener and after connecting the client, read the stream in pieces and save it to a file
class Program { static void Main() { var listener = new TcpListener(IPAddress.Loopback, 11000); listener.Start(); while (true) { using (var client = listener.AcceptTcpClient()) using (var stream = client.GetStream()) using (var output = File.Create("result.dat")) { Console.WriteLine("Client connected. Starting to receive the file");
As for sending, you can take a look at the example provided in the documentation of the SendFile method.
With that, you can also take a look at a more robust solution that WCF should use. Protocols exist, such as MTOM, which are specifically optimized for sending binary data over HTTP. This is a much more reliable solution compared to reliable connectors, which are very low. You will have to handle things like file names, presumably metadata, ... things that are already factored into existing protocols.
Darin Dimitrov
source share