Dear all.

I have the Hardware device which connected to http://www.usriot.com/p/rs485-to-wifi-converters/ above converter. I have connected 2 devices so far and Indivually working fine. I have written Small Vb code to get data from wifi and display on Vb screen. With above setup i am facing problem in software hangs

The software get hangs in 4 cases:
  1. Wifi device has low signal stregth
  2. wifi device is not powered on
  3. wifi device stop communication; problem facing opening client port
  4. Hardware device fail to send data.


This my client code to receive the data over wifi. With this I can able to update without any issue . unless wifi and hardware working fine
Code:
Sub Connect(ByVal server As [String], ByVal message As [String])
        Try
            ' Create a TcpClient.
            ' Note, for this client to work you need to have a TcpServer 
            ' connected to the same address as specified by the server, port
            ' combination.
            Dim Port1 As String
            Port1 = SMCB1_Port.Text
            Dim port As Int32 = CInt(Port1)
            Dim client As New TcpClient(server, port)

            ' Translate the passed message into ASCII and store it as a Byte array.
            Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)

            ' Get a client stream for reading and writing.
            '  Stream stream = client.GetStream();
            Dim stream As NetworkStream = client.GetStream()

            ' Send the message to the connected TcpServer. 
            stream.Write(data, 0, data.Length)

            Console.WriteLine("Sent: {0}", message)

            ' Receive the TcpServer.response.
            ' Buffer to store the response bytes.
            data = New [Byte](256) {}

            ' String to store the response ASCII representation.
            Dim responseData As [String] = [String].Empty

            ' Read the first batch of the TcpServer response bytes.
            Dim bytes As Int32 = stream.Read(data, 0, data.Length)
            responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
            Console.WriteLine("Received: {0}", responseData)

            ' Close everything.
            stream.Close()
            client.Close()
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: {0}", e)
        Catch e As SocketException
            Console.WriteLine("SocketException: {0}", e)
        End Try

        Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
        Console.Read()
    End Sub 'Connect
I have tried to modify code using client syntax by checking connected; avilable; active or not

https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

This is working fine with all true cases. But not working fine with false case.