Socket write behaviour is inconsistent?
- From: cjard <mcw8@xxxxxxxxxx>
- Date: Thu, 08 Nov 2007 08:24:05 -0800
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?
.
- Follow-Ups:
- Re: Socket write behaviour is inconsistent?
- From: Scott Gifford
- Re: Socket write behaviour is inconsistent?
- From: Jon Skeet [C# MVP]
- Re: Socket write behaviour is inconsistent?
- From: Peter Duniho
- Re: Socket write behaviour is inconsistent?
- Prev by Date: Re: C# 2005 Express Missing Features
- Next by Date: Re: C# 2005 Express Missing Features
- Previous by thread: Re: COM Interop.
- Next by thread: Re: Socket write behaviour is inconsistent?
- Index(es):
Relevant Pages
|