Problem to establish a connection between Client.exe and Server.exe using No-ip service

Asked

Viewed 110 times

0

I have a remote access app and needed to receive connections from my customers using the service No-ip (no-ip.com), in view of the fact that ip external is always dynamic. So I have already made all settings correctly (on the Server.exe side) such as:

  • I’ve cleared the necessary ports on the modem
  • I disabled the Windows firewall

So far I have not been successful to establish this connection (with local ip using Client.exe and Server.exe on the same network, works perfectly).

So I am 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 what might be going on and can help me with this serious problem?

I have tried several ways regarding the use of TcpClient.Connect() and class IPEndPoint, but so far no success.

However, any other suggestions will be welcome!

  • I think this question is outside the scope of the OS, but I’ll give you a hint. You have to do NAT on your router (something like VMZ). Look for how to do NAT on your router.

  • @Marcosregis, I did the proper procedure, but I was unsuccessful. With your experience as a VB.NET programmer, could you tell me if I’m going the right way with methods Conn and Connect above?

  • 1

    The problem is not programming, but network configuration. I have no experience with VB.NET using Socket Objects but as mentioned that the code works with another configuration, I can only believe that is Network problem.

  • @Marcosregis, I think you were right, I even thought this post which depicts exactly the same problem of mine, I followed the step by step that the author did there to solve, but here it did not work. Even, in relation to the suggested step 2, I did exactly the same see, and no firewall is active here. Here is your tip from DMZ. And my Tcplistener is like this: TL = New TcpListener(Ipaddress.Parse("192.168.25.116"), 100).

  • I believe I’m following all the tips correctly :-)

  • Desativei o firewall do Windows This is not a necessary setup and exposes your machine to risks.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.