Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3123
  • Last Modified:

How do you set a TCPClients Send/Receive Timeout when using the .NET Compact Framework?


I have a TCP/IP cleint application which uses the TCPClient object to communicate with a TCP server.  Occassionaly, I am getting the error "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."  I believe this is happening when the data stream become larger (> 1K). I am using asynchronous communications, BeginRead, EndRead, etc.   How can I prevent this error.  I noticed the SendTimeout, ReceiveTimeout properties on the TCPClient object, but they are not supported by the .NET Compact Framework.  What is the best way to handle this situation?

Thanks!
0
mromeo
Asked:
mromeo
  • 5
  • 4
  • 2
1 Solution
 
vo1dCommented:
user version 2.0, you will find it there.
0
 
mromeoAuthor Commented:
Unfortunately, that is not an option for me right now. You're saying there is no other way to do this?  Do you know of any docs that compare 1.1 and 2.0 functionality?  Maybe I can convince mgmt to upgrade.
0
 
vo1dCommented:
im sorry, i dont have any comparisons of the compact frameworks.
maybe you can find some information here:
http://msdn.microsoft.com/netframework/programming/netcf/default.aspx

i only knew that they have implemented much more functionallity in it, so that designtime can be reduced.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
elticCommented:
Although the TcpClient class in CF2.0 has the properties ReceiveTimeout and SendTimeout,
they are not supported. If you want to change the value, you'll get an exception. According
to the MSDN help:

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: In .NET Compact Framework applications, the ReceiveTimeout enumeration value is supported but reserved for future use. Because the ReceiveTimeout property uses this enumeration value, it will raise SocketException until the enumeration value is available in a future release of the .NET Compact Framework.

So, changing to CF2.0 will not work either. I think your only choice is to keep the data packages
in each BeginRead call as small as possible (e.g. 512 Byte or something).
0
 
mromeoAuthor Commented:
Yup, I was afraid of that.    Looks like it's back to the drawing board.

0
 
elticCommented:
By the way, event if it won't solve your problem, you should convince mgmt for upgrade, because it's faster (sometimes a speed-up factor of 10), and many basic things, e.g. XmlSerializer-class are implemented. (Not that there aren't other choices like Opennetcf, but it's more, let's say stable and more comaptible). Many performance problems in our app were solved by migrating.

Oh, I forgot: before you will face it as a problem: asynchronous data streaming isn't supported by the TcpClient class either. If you want to use it, you have to use to Socket-class instead.

Cheers,

Patrick
0
 
mromeoAuthor Commented:
Are you saying that the BeginRead, EndRead methods of the TCPCleint class aren't really asynchronous?
0
 
mromeoAuthor Commented:
I meant to say NetworkStream class...sorry.
0
 
elticCommented:
If you call the methods BeginRead or EndRead after retreiving the NetworkStream
by calling TcpClient.GetNetworkStream, you will get a NotSupportedException. They
are only provided, because the base class System.IO.Stream implements them.
0
 
mromeoAuthor Commented:
I am using the following code on a CE device.  I am using the .NET CF 1.1.  I am not getting any exceptions with this.  Is the the kind of code you are talking about?  My readCallack gets called with no problem.  The only time I have a problem is when the data coming back to the client gets too large.

try
{
      byte[] arrayData = Encoding.ASCII.GetBytes(sData);      

      NetworkStream commStream = this.m_tcpClient.GetStream();
                  
      commStream.Write(arrayData, 0, arrayData.Length);

      // Create the state object.
      StateObject state = new StateObject();
      state.workStream = commStream;
      state.callbackMethod = cbProc;

      if (commStream.CanRead)
      {
            IAsyncResult r = commStream.BeginRead(state.buffer, 0, StateObject.BufferSize,                                                       new AsyncCallback(readCallback), state);      
      }
}
catch (Exception ex)
{
      MessageBox.Show("Caught general exception: " + ex.ToString());
}

0
 
elticCommented:
Sorry, you're I had a underlying readonly stream (for data compression, which
can't handle async request). BeginRead and EndRead are "real" async methods.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now