A couple of months ago I started creating a socket wrapper to make creating socket connections a little easier.  Yesterday, I started working on it again and came across a ‘bug’ when setting the ReceiveBufferSize.  I wanted to make the SendBufferSize and ReceiveBufferSize changeble by the user. Here is the code:

// Set these socket options
this.tcpClient.SendBufferSize = this.sendBufferSize;
this.tcpClient.ReceiveBufferSize = this.receiveBufferSize;

The error returned when setting ReceiveBufferSize was “An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call”

Upon further investigation (and with help from Sandeep P.) by searching getsockopt and setsockopt from the error message I came accross this:

SO_RCVBUF int Specifies the total per-socket buffer space reserved for receives.
For Windows CE .NET 4.1 and later, the default buffer space is set to 8192 bytes. You can change the per-socket buffer space by calling setsockopt.

Note   This option is only supported for SOCK_DGRAM sockets.

So, basically Windows CE only supports setting the ReceiveBufferSize if you are using Datagrams (or UDP) and since I’m using TCP .NETCF throws the error.  It’s not really an bug, but something not supported by the underlying OS (Windows CE) which VS.NET2005 IDE let’s you see using IntelliSense. Don’t get me wrong IntelliSense has been greatly improved for Compact Framework (see here) and TCPClient.ReceiveBufferSize I’m sure is rarely used.

So if you’re doing some socket programming on a device be aware of this.  8K of buffer size should be big enough, but just be aware of this when using TCPClient.  

Note: On the desktop setting ReceiveBufferSize does not throw an exception. 

Warning: count(): Parameter must be an array or an object that implements Countable in /nfs/c07/h02/mnt/110221/domains/ on line 405

Leave a Reply