C# TcpClient TcpListener Cant send very large files 11-18-2016, 10:50 PM
#1
Hi all,
So I have my server and client application, I use the below code for handling incoming and outgoing messages:
So first it reads the amount of bytes to send, sends that information so a specific byte array of that size will be prepared to read the message, it works perfectly but when sending large files of 10MB or more only a part arrives, I tried to google it but couldnt find the answer, some people suggested to keep on reading untill the stream ends but i dont really know how to do that, if anyone could point me out.
Thanks
So I have my server and client application, I use the below code for handling incoming and outgoing messages:
Code:
while ((true))
{
try
{
byte[] buffer = new byte[4];
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
buffer = new byte[4];
int readBytes = networkStream.Read(buffer, 0, 4);
if (readBytes == 0)
break;
int MessageSize = BitConverter.ToInt32(buffer, 0);
byte[] bufferreader = new byte[MessageSize];
readBytes = networkStream.Read(bufferreader, 0, MessageSize);
if (readBytes == 0)
break;
dataFromClient = Encoding.ASCII.GetString(bufferreader);
Console.WriteLine(Convert.ToString(MessageSize));
rCount = Convert.ToString(requestCount);
byte[] outbuffer = new byte[4];
serverResponse = R.Respond(dataFromClient, K);
sendBytes = Encoding.ASCII.GetBytes(serverResponse);
outbuffer = new byte[4];
outbuffer = BitConverter.GetBytes(sendBytes.Length);
networkStream.Write(outbuffer, 0, 4);
networkStream.Flush();
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Flush();
}
catch (Exception ex)
{
Console.WriteLine("User Server >> " + ex.ToString());
Thread.CurrentThread.Abort();
}
}Thanks
Jabber: fuhrer@0day.ms
I2P-Bote: Code:
lLX7Z6LDnFbHc67Kv9GR3YCDAfSot7vNy1g2jwUNFhKGgwksYk8Y6bGQnRRiMfQHQvSM0yheDlWEhFpmSoW7MH9oYSrNVHoMbwRxu2jib2DS-OzbmUKlVzmOuyfRARnK7vinu78aYhCqH9eeJhwvk4JNtBEhD2K1hzpGeXxkDu3Zct

![[+]](https://sinister.li/images/modern/collapse_collapsed.png)















