Re: Socket write behaviour is inconsistent?
- From: Scott Gifford <sgifford@xxxxxxxxxxxxxxxx>
- Date: Mon, 12 Nov 2007 00:26:05 -0500
cjard <mcw8@xxxxxxxxxx> writes:
[...]
THIS FAILS:
socket.Send(new byte[]{ 0x02 }); //send start
socket.Send(response); //send start
socket.Send(new byte[]{ 0x03 }); //send start
it fails because the client throws an error that EOT was encountered
from the host
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)
[...]
As others have suggested, look at this with a packet sniffer.
A common bug in C socket programming is something like this:
char buf[8192];
read(socket_fd, buf, 8192);
if (!strchr(buf,'\x03')) {
/* Error! */
}
If three different packets are sent, read() can return 3 times, each
time with part of the packet.
It's possible that the first example sends 3 different packets, and
the second sends just one. In that case, the first example would
expose this bug, while the second would work around it (or mask it,
depending on your viewpoint).
One possibility is to make sure Nagle's algorithm is enabled (that is,
the NODELAY option is turned off) on the sending socket. This may
combine the multiple Send's into one, although it's not guaranteed.
Another possibility is to just use one of the two examples that works.
:-)
Good luck!
----Scott.
.
- Follow-Ups:
- Re: Socket write behaviour is inconsistent?
- From: Peter Duniho
- Re: Socket write behaviour is inconsistent?
- References:
- Socket write behaviour is inconsistent?
- From: cjard
- Socket write behaviour is inconsistent?
- Prev by Date: Re: Help a newbie with method.method?
- Next by Date: Concurrency and delegates
- Previous by thread: Re: Socket write behaviour is inconsistent?
- Next by thread: Re: Socket write behaviour is inconsistent?
- Index(es):
Relevant Pages
|
Loading