2010年5月2日 星期日

[.NETCF]How to setting Send/Receive buffer with .NET Socket

Introduction
When implement a TCP/IP program with socket, generally we need to send some long data,
but design a message format is miscellaneous behavior.
So I try to modify Send/Receive buffer size to solve it.

Background
When I implement socket program with M$ .NET Framework, I found that only need to modify Socket property to solve it.
But in my job, I will implement this function in WinCE system with .NET Compact Framework.
And the .NETCF socket has not Send/Receive buffer size property, so I need anthoer solution to implement it.

Solution
In Windows .Net, we can use propery to set.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
s.SendBufferSize = 102400;
s.ReceiveBufferSize = 102400;
(Default value is 8192)

but .NET CF2.0 has not SendBufferSize/ReceiveBufferSize property.
so we can do this

s.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveBuffer, 102400);
s.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendBuffer, 102400);

沒有留言:

張貼留言

Hello