ReuseAddress and the Compact framework

  • Thread starter Thread starter afonso.ricardo
  • Start date Start date
Can you post a snippet of the problem code you are using to call setsockopt?

Peter
 
But of course...

This code was inspired by another post in this forum (credit were it's
due). Unfortunately the post didn't answer the question completely

Here it goes:

Invocation (SendSocket is a regular .NET Socket):

this.SetSocketOption(SendSocket.Handle, SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress, 1) ;

(Wrapper function to call setsockopt Interop)
public int SetSocketOption(IntPtr m_Handle,SocketOptionLevel
optionLevel, SocketOptionName optionName, int optionValue)
{

return
setsockopt(
m_Handle,
optionLevel,
optionName,
ref optionValue,
Marshal.SizeOf(optionValue));
}

(setsockopt interop declaration)
[DllImport("Winsock",EntryPoint="setsockopt", CharSet=CharSet.Auto,
SetLastError=true)]
public extern static int setsockopt(IntPtr _sock, SocketOptionLevel
level, SocketOptionName name, ref int optionValue, int int_val);

Here it is...

Thanks in advance for your help.

Ricardo Afonso
 
Back
Top