Control ip relay device from internet web page using tcp RRS feed

  • Question

  • i wrote some code to control an ip device, i made in windows forms application , silverlight and asp.net, they all work on the local network , but won't work from internet web server, i have the router forwarding to local device ip and port,
    i get this 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 226.45.306.158:4999

    here's the code used

     Private Function SendRelayCommandTest(ByVal e As String) As String
            'SendTextToIP("setstate,1:" & thePort & "," & TheState)
            'Dim IPHostCC1 As String = ""
            Dim IPHostCC1 As String = "226.45.306.158"
            Dim IPHostPort As Integer = 49989       	
            Dim tcpClient As New System.Net.Sockets.TcpClient()
            tcpClient.Connect(IPHostCC1, IPHostPort)
            Dim networkStream As NetworkStream = tcpClient.GetStream()
            Dim strResponse As String
            Dim strCommand As String
            strCommand = e ' RelayEventArgs.SetState & ",1:" & e.Port & "," & e.State
            strResponse = "No response"
                If networkStream.CanWrite Then
                    Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strCommand & vbCr)
                    networkStream.Write(sendBytes, 0, sendBytes.Length)
                    Dim bytes(tcpClient.ReceiveBufferSize) As Byte
                    networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                    Dim returndata As String = Encoding.ASCII.GetString(bytes)
                    strResponse = "Return: " & CStr(returndata)
                    If Not networkStream.CanWrite Then
                        strResponse = "Error: Cannot write data to the Relay device"
                    End If
                End If
            Catch ex As ArgumentNullException
                strResponse = "ArgumentNullException: " & ex.Message
            Catch ex As SocketException
                strResponse = "SocketException: " & ex.Message
            Catch ex As Exception
                strResponse = "Exception: " & ex.Message
            End Try
            Return strResponse
        End Function 

    is there a diffrent method to use over internet ?
    Thursday, April 26, 2012 1:32 PM


All replies