[Mono-list] Socket code.

George Farris george@gmsys.com
Sun, 22 Feb 2004 10:06:51 -0800


On Sun, 2004-02-22 at 01:17, Michal Moskal wrote:
> On Sat, Feb 21, 2004 at 04:31:00PM -0800, George Farris wrote:
> > I have some socket code that looks something like this:
> > 
> > byte[] bytes = new byte[1448];
> > do {
> > 	len = sock.Read(bytes, 0, (int)1448);
> > 	s = Encoding.ASCII.GetString(bytes);
> > 	buf.Append(s.Substring(0,len));
> 
> Shouldn't it be:
> 
>  	s = Encoding.ASCII.GetString(bytes, 0, len);
>  	buf.Append(s);
> 

Well the docs on GetString say it can be just a byte[].  

The interesting thing is the length which only works as 1448 which is a
number I found by printing out the len variable.  If I set the byte[] to
say 10000, sock.read (which should really be named stream.read as it's a
NetworkStream) always returns anywhere from 0 to 1448 bytes but never
more.

I also tried the example from the .NET docs and it doesn't work either. 
It reads up to 1448 bytes and the stops.  The code is here:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemnetsocketsnetworkstreamclassreadtopic.asp?frame=true

-- 
George Farris <george@gmsys.com>