SendTimeout and ReceiveTimeout for socket at CompactFramework

  • Thread starter Francisco K. do Amaral
  • Start date
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"
 
C

Chris Tacke, eMVP

Windows CE itself doesn't support the timeouts, so the CF can't.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Francisco K. do Amaral said:
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,
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"
 
F

Francisco K. do Amaral

Ok,

So, how can I continue my application when it's blocked because I call the
receive method and the hardware connection (cradle) was broken?
And how about the Receive and Send Buffer properties? It's not supported
too?

thanks

Windows CE itself doesn't support the timeouts, so the CF can't.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Francisco K. do Amaral said:
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,
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"
 
D

Dick Grier

Hi,

This depends on the details involved in the call to "the receive method"
that you mention. What receive method? Perhaps there is a non-blocking
substitute? To what Receive and SendBuffer properties do you refer?

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top