I have a remote access application and needed to receive connections from my clients using the No-ip
service (no-ip.com), since external ip is always dynamic.
So I've already done all the settings correctly (from the Server.exe side) such as:
- I have released the required ports on the modem
- Disable Windows Firewall
So far I have not succeeded in establishing this connection (with local ip using Client.exe and Server.exe on the same network, it works perfectly).
So, I'm currently using the following code below to try to establish this connection
using the service No-ip
(no-ip.com):
Public Class SocketClient
Private C As TcpClient
Public Function IsIPAddressValid(ByVal addrString As String) As Boolean
Dim address As IPAddress
Return IPAddress.TryParse(addrString, address)
End Function
Sub Connect(ByVal h As String, ByVal p As Integer)
Dim ipAddr As System.Net.IPAddress
Dim ipEndPoint As System.Net.IPEndPoint
Try
Try
If C IsNot Nothing Then
C.Close()
C = Nothing
End If
Catch ex As Exception
End Try
Do Until IsBuzy = False
Threading.Thread.CurrentThread.Sleep(1)
Loop
Try
ipAddr = IPAddress.Parse(h)
ipEndPoint = New System.Net.IPEndPoint(ipAddr, p)
C = New TcpClient(ipEndPoint)
C.Connect(ipEndPoint)
MessageBox.Show("Ok") ' Devido ao erro, esta mensagem nunca aparece
Dim t As New Threading.Thread(AddressOf RC, 10)
t.Start()
RaiseEvent Connected()
Catch ex As Exception
End Try
Catch ex As Exception RaiseEvent Disconnected()
End Try
End Sub
Function conn() As String
Dim inStream As StreamReader
Dim webRequest As WebRequest
Dim webresponse As WebResponse
Dim ip As String = Nothing
Dim tfk As New Thread(Sub()
Try
webRequest = webRequest.Create(Decrypt1("kTbXQyC7KwzyNTyQNzfQqN0rg2CMhKdwNWvBts6hS7Q=")) 'Url para o arquivo .txt remoto
webresponse = webRequest.GetResponse()
inStream = New StreamReader(webresponse.GetResponseStream())
ip = inStream.ReadToEnd()
If Not IsIPAddressValid(ip) Then
Dim hostname As IPHostEntry = Dns.GetHostByName(ip) ' Pega o endereço No-ip contido no arquivo .txt remoto
Dim Noip As IPAddress() = hostname.AddressList
ip = Noip(0).ToString() 'Endereço No-ip convertido para o ip externo correspondente
End If
Catch ex As Exception
End Try
End Sub)
tfk.Start()
tfk.Join()
Return ip
End Function
End Class
'' '' '' '' 'Form1.vb (Client.exe)' '' '' '' '' '' '
Public Class Form1
Public WithEvents C As New SocketClient
Public HOST As String = Nothing
Public port As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
HOST = C.conn
Dim port = 92
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If C.Statconnected = False Then
C.Connect(HOST, port)
End If
End Sub
End Class
Does anyone have any idea of what might be happening and can help me with this serious problem?
I have tried in many ways with the use of TcpClient.Connect()
and class IPEndPoint
, but so far nothing successful.
However, any other suggestions will be welcome!