Re: Socket write behaviour is inconsistent?
- From: cjard <mcw8@xxxxxxxxxx>
- Date: Fri, 09 Nov 2007 08:47:01 -0800
Is "tmp[tmp.Length -2]" a typo? Seems like that should be
"tmp[tmp.Length - 1]" instead.
It is a typo, sorry
[...]
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.
I'd assert I have. The concept is that the following approaches ought
to be equivalent:
a) Send 1 byte, Send many bytes, Send 1 byte
b) copy 1 byte to buffer, copy many bytes to buffer, copy one byte to
buffer, send entire buffer
c) make a list of 3 ArraySegment<byte>
For that
matter, you haven't really even described the behavior precisely enough
(on what statement exactly is the exception thrown?).
There is no exception. The client device is a relatively dumb terminal
- a credit card terminal to be precise. When I interact with it in the
first way, it drops the conenction and contacts the server again, each
time spitting out a piece of paper saying "End of Transmission from
host"
Interact with it in the latter two ways and it works perfectly.
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.
The terminating 0x03 is mandatory, as far as the spec is concerned.
There is a device in between the terminal and the server in the form
of a terminating unit that connects the british X25 network, with the
local LAN, which could in theory add these bytes itself, but I doubt
that it does this, because attempting to send just the message buffer
without the requisite 0x02 / 0x03 fails.
Either would explain why the server might close the connection before
you get a chance to send that last byte.
The server isnt supposed to close the connection; the dumb client gets
(some of?) whatever I send, dumps the connection and retries. I find
out the connection was dropped because I return to Read() on a
blocking socket and some time later it unblocks having read 0 bytes
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.
Indeed, and I totally agree. THere is a small problem with this
though; If you have a spare credit card terminal, a connection to the
british X25 or a company that can arrange this, an ACP device to
provide the necessary X25 <> TCP link then I'll gladly send some
working code. As it is, those things are usually pretty hard to come
by to run a quick test :(
Such is the difficulty of debugging the situation; all i know is that
sending piecemeal doesnt work, and sending in one go does. Indeed the
TCP-ness of the chain will only go as far as our ACP before it reverts
to X25. Most irritating.
.
- Follow-Ups:
- Re: Socket write behaviour is inconsistent?
- From: Mike Blake-Knox
- Re: Socket write behaviour is inconsistent?
- From: Peter Duniho
- Re: Socket write behaviour is inconsistent?
- References:
- Socket write behaviour is inconsistent?
- From: cjard
- Re: Socket write behaviour is inconsistent?
- From: Peter Duniho
- Socket write behaviour is inconsistent?
- Prev by Date: Re: system.web and HttpContext
- Next by Date: Re: Socket write behaviour is inconsistent?
- Previous by thread: Re: Socket write behaviour is inconsistent?
- Next by thread: Re: Socket write behaviour is inconsistent?
- Index(es):
Relevant Pages
|