I want to send a File via sockets in C#. I am using a server and a client.
Server:
static void Main(string[] args)
{
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
server.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 100));
server.Listen(0);
Socket client = server.Accept();
client.SendFile("F:\\TestMovie.mp4");
server.Close();
Console.ReadKey();
}
Client:
static void Main(string[] args)
{
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 100));
byte[] buff = new byte[10048];
int index = client.Receive(buff);
if (buff.Length < index)
{
Array.Resize<byte>(ref buff, index);
}
File.WriteAllBytes("F:\\TestMovie.mp4", buff);
}
I mean How can Client know how many size the server is sending.
This is kinda simple since I just used it as a test.
But the server can only send files with sizes which are only about 10KB.