F
Francisco K. do Amaral
Hi,
I'm having trouble to set SendTimeout and ReceiveTimeout for a socket at
CompactFramework.
Although it's supported by .NET CF, when i try to use the method
SetSocketOption it's always throw a exception.
When I try to get the default value for this properties it's work and
return -1 (undefined time).
The error also occurs when I try to get the option SendBuffer, but not
occurs when I try get the option ReceiveBuffer!!
It's not strange!?!?!
Seting the SendBuffer or the ReceiveBuffer the socketException is throw too.
This is my code:
Socket tcp = new Socket( AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );
//It's OK.
MessageBox.Show( BitConverter.ToInt32( tcp.GetSocketOption(
SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4),0).ToString() );
//It's OK.
MessageBox.Show( BitConverter.ToInt32( tcp.GetSocketOption(
SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout,
4),0).ToString() );
//It's OK.
byte[] bytRec
=tcp.GetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveBuffer
, 4 );
//Will throw SocketException
byte[] bytSnd =
tcp.GetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendBuffer,
4 );
//Will throw SocketException
tcp.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveBuffer,
10240);
tcp.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendBuffer,102
40);
tcp.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
BitConverter.GetBytes( 60000 ));
tcp.SetSocketOption( SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, BitConverter.GetBytes( 60000 ));
This is the exception message:
"An unhandled exception of type 'System.Net.Sockets.SocketException'
occurred in System.dll
Additional information: An unknown, invalid, or unsupported option or level
was specified in a getsockopt or setsockopt call"
I'm having trouble to set SendTimeout and ReceiveTimeout for a socket at
CompactFramework.
Although it's supported by .NET CF, when i try to use the method
SetSocketOption it's always throw a exception.
When I try to get the default value for this properties it's work and
return -1 (undefined time).
The error also occurs when I try to get the option SendBuffer, but not
occurs when I try get the option ReceiveBuffer!!
It's not strange!?!?!
Seting the SendBuffer or the ReceiveBuffer the socketException is throw too.
This is my code:
Socket tcp = new Socket( AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );
//It's OK.
MessageBox.Show( BitConverter.ToInt32( tcp.GetSocketOption(
SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4),0).ToString() );
//It's OK.
MessageBox.Show( BitConverter.ToInt32( tcp.GetSocketOption(
SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout,
4),0).ToString() );
//It's OK.
byte[] bytRec
=tcp.GetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveBuffer
, 4 );
//Will throw SocketException
byte[] bytSnd =
tcp.GetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendBuffer,
4 );
//Will throw SocketException
tcp.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveBuffer,
10240);
tcp.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendBuffer,102
40);
tcp.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
BitConverter.GetBytes( 60000 ));
tcp.SetSocketOption( SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, BitConverter.GetBytes( 60000 ));
This is the exception message:
"An unhandled exception of type 'System.Net.Sockets.SocketException'
occurred in System.dll
Additional information: An unknown, invalid, or unsupported option or level
was specified in a getsockopt or setsockopt call"