I am trying to send *.pdf file and save it on second machine. Im using following code to send:
IPHostEntry ipHost = Dns.GetHostEntry("127.0.0.1");
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect(ipEndPoint);
Console.WriteLine("Sending {0} to the host.", fileName);
client.SendFile(file);
client.Shutdown(SocketShutdown.Both);
client.Close();
And following to save file:
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("C:/ODEBRANE/result.pdf"))
{
Console.WriteLine("Client connected. Starting to receive the file");
// read the file in chunks of 1KB
var buffer = new byte[1024];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
}
Now, question is, how can I get file name same as on client side? without renaming it to "result"? Is there any possibility to send that name with file and use it on server side?