Re: Socket write behaviour is inconsistent?




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.

.



Relevant Pages

  • Re: why does scp not use all my cores on a multi-cpu machine?
    ... The buffer size issue is actually part of the I/O bottleneck. ... In the FAQ for hpn-ssh there is an important couple of Q&As ... is the speed of your network connection to the Internet. ...
    (comp.os.linux.misc)
  • Re: Windows buffering downloaded data?
    ... whenever I start to download a file or watch a video ... When I test the network download speed with that computer, ... buffer is full (or the connection is closed before the buffer getting full) ...
    (microsoft.public.windowsxp.network_web)
  • Re: Windows buffering downloaded data?
    ... whenever I start to download a file or watch a video etc. from the net it takes really long time before anything starts to happen. ... When I test the network download speed with that computer, first it takes forever before the test starts to download the data and then it’s suddenly over and the test results shows that my network speed is something like 55M. ... It seems like the PC is buffering the data coming in and only then, when the buffer is full (or the connection is closed before the buffer getting full) the PC uses the data. ...
    (microsoft.public.windowsxp.network_web)
  • Windows buffering downloaded data?
    ... whenever I start to download a file or watch a video ... When I test the network download speed with that computer, ... buffer is full (or the connection is closed before the buffer getting full) ...
    (microsoft.public.windowsxp.network_web)
  • Re: Pre-Dial (et. al.) geo, Wherefore art thou Pre-Dial (et. al.) geo...
    ... this service offers callthrough to various international destinations as ... the termination charges payable by BT to another operator (in the ... day and the distance the call was carried by BT across their network. ...
    (uk.telecom)