1

I have mobile RF terminal with Windows CE 6.0 CF 3.5 and I need send data as quickly as possible to my server. Problem is that wifi connection is not stable enough in place of use. I reduced the loss of data with repeated sending when connection is aborted by exception. But time for exception is ~21sec and it's too long for me. Repeated connections are successful (mostly), but I need shorten time for exception, or find different method for connection.

For data receive I have TCP server in terminal. And here I have one thread with timer and after my timeout I close client (TcpClient) and catch exception from this :-). But I mean that this method is not ideal.

Any ideas?? Thanks!

Below is my code for TCP client connection

    internal string TCPsend(string strMessage)
    {
        string exception = string.Empty;
        TcpClient client = null;
        try
        {
            client = new TcpClient(IPServer, PortServer);
            client.SendTimeout = 500;                        //no effect
            Stream stream = client.GetStream();
            StreamWriter strWriter = new StreamWriter(stream);
            strWriter.Write(strMessage);
            strWriter.Close();
        }
        catch (Exception ex)
        {
            exception = ex.ToString();
            utility.SaveExceptionLog("SendTCP A: " + ex.ToString());
        }
        finally
        {
            if (client != null)
            {
                client.Close();
            }
        }
        return exception;
    }
zdenál
  • 73
  • 7
  • In the code you have posted, the majority of the time will be spent opening and closing the connection, It is far more efficient to keep the connection open and use a periodic heartbeat message to detect a network break in the absence of other traffic to do so. – tcarvin Feb 19 '14 at 13:20

1 Answers1

0

If you want to take connectivity check into your hands, probably you should open new thread, where you will check in a loop for an established connection.

Here is the answer where the trivial check disscussed: What is the best way to check for Internet connectivity using .NET?

This will impact on overall sending performance, but should reduce the waiting time.

Community
  • 1
  • 1
Rodion
  • 886
  • 10
  • 24