Last post May 01, 2012 06:00 AM by Anik Sh - MSTF
Apr 26, 2012 09:13 PM|GATMAN|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()
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"
Catch ex As ArgumentNullException
strResponse = "ArgumentNullException: " & ex.Message
Catch ex As SocketException
strResponse = "SocketException: " & ex.Message
Catch ex As Exception
strResponse = "Exception: " & ex.Message
is there a diffrent method to use over internet ?
do i need to use callbacks, or set some timeouts somewhere.
Apr 30, 2012 02:50 PM|Curt_C|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.
Apr 30, 2012 03:19 PM|GATMAN|LINK
it's on a godaddy.com shared hosting, can't run windows app on it.
Apr 30, 2012 04:29 PM|Curt_C|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.....
May 01, 2012 06:00 AM|Anik Sh - MSTF|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.