L
Lars
Hi! I´m trying to send a file over a network with tcp/ip
so that the client can download it and save it. I going to
send the size of the file in a textmessage but I have not
implemented that part yet. But am I getting in right?
This is the server (not all).
Socket client = server.Accept();
NetworkStream netStream = new NetworkStream(client);
FileStream file = new FileStream
("c:\\test.doc",FileMode.Open, FileAccess.Read);
FileInfo info = new FileInfo("c:\\test.doc");
int len = (int)info.Length;
Console.WriteLine(len);
byte [] b = new byte[50 * 1024];
int count = 0;
while(count != len)
{
count = file.Read(b, 0, len);
netStream.Write(b, 0, len);
Console.WriteLine(count);
}
And the client:
FileStream file = new FileStream("c:\\test2.doc",
FileMode.Create);
byte [] b = new byte[50 * 1024];
int len = 19456; //Size of file, should be sent.
int count = 0;
for(count = 0; count <= len; count++)
{
int i = netStream.Read(b, 0, len);
file.Write(b, 0, len);
Console.WriteLine("Klient: " + i);
}
so that the client can download it and save it. I going to
send the size of the file in a textmessage but I have not
implemented that part yet. But am I getting in right?
This is the server (not all).
Socket client = server.Accept();
NetworkStream netStream = new NetworkStream(client);
FileStream file = new FileStream
("c:\\test.doc",FileMode.Open, FileAccess.Read);
FileInfo info = new FileInfo("c:\\test.doc");
int len = (int)info.Length;
Console.WriteLine(len);
byte [] b = new byte[50 * 1024];
int count = 0;
while(count != len)
{
count = file.Read(b, 0, len);
netStream.Write(b, 0, len);
Console.WriteLine(count);
}
And the client:
FileStream file = new FileStream("c:\\test2.doc",
FileMode.Create);
byte [] b = new byte[50 * 1024];
int len = 19456; //Size of file, should be sent.
int count = 0;
for(count = 0; count <= len; count++)
{
int i = netStream.Read(b, 0, len);
file.Write(b, 0, len);
Console.WriteLine("Klient: " + i);
}