Socket write behaviour is inconsistent?



I have a client and server that enjoy the following simple dialogue:

Client connects
Client sends request
Server sends response
Client disconnects

This is the way it must be. The response must be wrapped in a start
and end byte 0x02 and 0x03 resepctively.

suppose I have a byte[] response:

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)


THIS WORKS:
List<ArraySegment<byte>> tmp = new List<ArraySegment<byte>>();
tmp.Add(new ArraySegment<byte>(new byte[]{ 0x02 }));
tmp.Add(new ArraySegment<byte>(response));
tmp.Add(new ArraySegment<byte>(new byte[]{ 0x03 }));
socket.Send(tmp);


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?

.



Relevant Pages

  • Re: ssh through vista connection sharing not working, NEW INFO: 802.1q headers from vista
    ... The ssh client is a linux laptop. ... connection with wireshark, and I see the response from the ssh server, ... Connection sharing is turned on in the Vista. ...
    (comp.os.linux.networking)
  • Re: How can I detect a carriage return using java.net
    ... With all due respect, I think that the connection should always be opened and closed by the client: if the server closes the connection you have no way of telling if the network broke, the server crashed or if it was an intentional "end of dialog" closure. ... the end of the response is. ...
    (comp.lang.java.programmer)
  • Re: async i/o completion routines, threading question
    ... the client does a WebRequest.Createand writes the post to the time the ... server logs receiving it. ... HttpListener stuff on the server side, but 13 seconds to open a connection ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework)
  • Re: Client/Service relationships & Flow of Requirements.
    ... the client calls "foo" when it wants "bar" to return a particular value. ... The following is designed to compel Prey objects to do something: ... predator < 100 yards from prey ... It is the expectation of the response that makes the runFrom name immediately suspect in an OO context. ...
    (comp.object)
  • Re: Client Server
    ... Otherwise, read a file in via a stream, make any required updates, and write ... > myself and compares it to the data that the client has sent to ... My response, though it was very general in nature, assumed exactly what you ... at some point you want the server to read this file in. ...
    (comp.lang.java.help)