C
Christopher H. Laco
I'm having a problem with the TcpClient that I can only conclude is
either a feature, or a complete misunderstanding of the docs on my part.
In a nutshell, I'm simply performing the following sequence with a server:
connect
write(50 bytes)
read(2002 bytes)
write(50 bytes)
read(2002 bytes)
write(50 bytes)
read(2002 bytes)
disconnect
At random times, one of the read sequences will read only 1460 bytes
instead of 2002 bytes. The reaminder, 542 bytes, just happens to fall on
a packet boundry. More on that later.
Now, for the sake of this argument, the number of times the write/read
sequence could happen per connection is unknown. Could be once; could be
20 times.
Now for some somewhat real code...
TcpClient client = new TcpClient();
client.NoDelay = true;
client.Client.Blocking = true;
client.Connect("remote_server", 3456);
for (int i = 1; i++; i <= 3) {
Byte[] outputbuffer;
NetworkStream stream;
outputbuffer = Encoding.ASCII.GetBytes("50 bytes of data...");
stream = this.GetStream();
stream.Write(outputbuffer, 0, outputbuffer.Length);
Byte[] inputbuffer;
inputbuffer = new Byte[2002];
Debug.WriteLine(stream.Read(inputbuffer, 0,inputbuffer.Length));
}
client.Close();
Now, sometimes when I run this, I get:
2002
2002
1460
Or this:
1460
2002
2002
OR this:
2002
1460
2002
Clearly, Socket.Blocking is not doing what I expect.
Sockst docs say that BLocking is on by default, so shouldn't it be doing
so, or is this a matter of the NetworkStream not doing something right?
Should I be using the Socket.Send/Receive methods instead?
At this point, I'm quite confused about the interaction of Socket vs.
NetworkStream within the TcpClient.
Thanks,
-=Chris
either a feature, or a complete misunderstanding of the docs on my part.
In a nutshell, I'm simply performing the following sequence with a server:
connect
write(50 bytes)
read(2002 bytes)
write(50 bytes)
read(2002 bytes)
write(50 bytes)
read(2002 bytes)
disconnect
At random times, one of the read sequences will read only 1460 bytes
instead of 2002 bytes. The reaminder, 542 bytes, just happens to fall on
a packet boundry. More on that later.
Now, for the sake of this argument, the number of times the write/read
sequence could happen per connection is unknown. Could be once; could be
20 times.
Now for some somewhat real code...
TcpClient client = new TcpClient();
client.NoDelay = true;
client.Client.Blocking = true;
client.Connect("remote_server", 3456);
for (int i = 1; i++; i <= 3) {
Byte[] outputbuffer;
NetworkStream stream;
outputbuffer = Encoding.ASCII.GetBytes("50 bytes of data...");
stream = this.GetStream();
stream.Write(outputbuffer, 0, outputbuffer.Length);
Byte[] inputbuffer;
inputbuffer = new Byte[2002];
Debug.WriteLine(stream.Read(inputbuffer, 0,inputbuffer.Length));
}
client.Close();
Now, sometimes when I run this, I get:
2002
2002
1460
Or this:
1460
2002
2002
OR this:
2002
1460
2002
Clearly, Socket.Blocking is not doing what I expect.
Sockst docs say that BLocking is on by default, so shouldn't it be doing
so, or is this a matter of the NetworkStream not doing something right?
Should I be using the Socket.Send/Receive methods instead?
At this point, I'm quite confused about the interaction of Socket vs.
NetworkStream within the TcpClient.
Thanks,
-=Chris