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
i tested the forms application from outside the lcal network and it works ok.
here's the code used
Private Function SendRelayCommandTest(ByVal e As String) As String
'SendTextToIP("setstate,1:" & thePort & "," & TheState)
'Dim IPHostCC1 As String = "192.168.1.105"
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"
Try
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)
Else
If Not networkStream.CanWrite Then
strResponse = "Error: Cannot write data to the Relay device"
tcpClient.Close()
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
Finally
tcpClient.Close()
networkStream.Close()
End Try
Return strResponse
End Function
is there a diffrent method to use over internet ?
do i need to use callbacks, or set some timeouts somewhere.
Where is your webserver? If you have access, can you put your windows app on that same server and try it? That will ensure it's not a routing issue in between somewhere.
Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
That's likely part of the problem then. They may not be allowing traffic out on those ports. You may want to submit a ticket to them and see if they run any port blocking, etc.....
Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
Marked as answer by Allen Li - MSFT on May 03, 2012 10:01 AM
You may capture network monitor log to trace traffic, if possible capture trace from both client and server at the same time when reproduce the issue. Also, you may check IIS log to see if the request reach the server. It seems network issue.
Marked as answer by Allen Li - MSFT on May 03, 2012 10:01 AM
GATMAN
0 Points
7 Posts
Control an IP Relay device from internet web server
Apr 26, 2012 08:13 PM|LINK
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
i tested the forms application from outside the lcal network and it works ok.
here's the code used
Private Function SendRelayCommandTest(ByVal e As String) As String 'SendTextToIP("setstate,1:" & thePort & "," & TheState) 'Dim IPHostCC1 As String = "192.168.1.105" 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" Try 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) Else If Not networkStream.CanWrite Then strResponse = "Error: Cannot write data to the Relay device" tcpClient.Close() 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 Finally tcpClient.Close() networkStream.Close() End Try Return strResponse End Functionis there a diffrent method to use over internet ?
do i need to use callbacks, or set some timeouts somewhere.
Thanks
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: Control an IP Relay device from internet web server
Apr 30, 2012 01:50 PM|LINK
it should still work.....
Where is your webserver? If you have access, can you put your windows app on that same server and try it? That will ensure it's not a routing issue in between somewhere.
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
GATMAN
0 Points
7 Posts
Re: Control an IP Relay device from internet web server
Apr 30, 2012 02:19 PM|LINK
it's on a godaddy.com shared hosting, can't run windows app on it.
George
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: Control an IP Relay device from internet web server
Apr 30, 2012 03:29 PM|LINK
That's likely part of the problem then. They may not be allowing traffic out on those ports. You may want to submit a ticket to them and see if they run any port blocking, etc.....
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
Anik Sh - MS...
Member
63 Points
16 Posts
Re: Control an IP Relay device from internet web server
May 01, 2012 05:00 AM|LINK
You may capture network monitor log to trace traffic, if possible capture trace from both client and server at the same time when reproduce the issue. Also, you may check IIS log to see if the request reach the server. It seems network issue.