Re: Socket write behaviour is inconsistent?
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 8 Nov 2007 11:24:08 -0800
On 2007-11-08 08:24:05 -0800, cjard <mcw8@xxxxxxxxxx> said:
[...]
THIS WORKS:
byte[] tmp = new byte[response.Length + 2]
Array.Copy(response 0, tmp, 1);
tmp[0] = 0x02;
tmp[tmp.Length -2] = 0x03;
socket.send(tmp)
Is "tmp[tmp.Length -2]" a typo? Seems like that should be "tmp[tmp.Length - 1]" instead.
[...]
I enabled network tracing and in all cases the bytes written are the
same, same number of them, but the logs do look different in the first
case (3 calls to Send instead of jsut 1)
Can anyone shed any light on why these work any differently?
You haven't posted enough code to answer definitively. For that matter, you haven't really even described the behavior precisely enough (on what statement exactly is the exception thrown?).
However, since normally it should not matter how you send the bytes (that is, whether they are grouped in a single array or are sent one at a time, or something in between), that suggests that either the termination byte 0x03 is optional, or the data contained in the "response" buffer already includes a termination byte.
Either would explain why the server might close the connection before you get a chance to send that last byte.
If that's not it, then you should post a concise-but-complete sample of code that reliably demonstrates the problem. Note that for networking code, "complete" means both ends of the connection. The point of "complete" is so that someone can actually run and test your code.
Pete
.
- Follow-Ups:
- Re: Socket write behaviour is inconsistent?
- From: cjard
- Re: Socket write behaviour is inconsistent?
- References:
- Socket write behaviour is inconsistent?
- From: cjard
- Socket write behaviour is inconsistent?
- Prev by Date: Implementing a Custom Download Manager and Integerating it with IE
- Next by Date: Re: How: multiple program instances sharing same data
- Previous by thread: Socket write behaviour is inconsistent?
- Next by thread: Re: Socket write behaviour is inconsistent?
- Index(es):
Loading