Results 1 to 6 of 6

Thread: [RESOLVED] VB.Net TCPClient Connection Error 10049

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    25

    Resolved [RESOLVED] VB.Net TCPClient Connection Error 10049

    Hey,

    I'm trying to make a server/client application that uses a TcpListener on the server-side which listens on my WAN IP (using IPAddress.Any method) and port 3000, and a TcpClient on the client-side, which connects to the server using a tcpClient.Connect(ipString, portNo), but this blocks for a number of seconds, after which it throws the error:

    A connection attempt failed because the connected party did not respond properly after a period of time, or established connection failed because connected host has failed to respond.

    A few points:

    - I have checked, using the VS debugger, that IPAddress.Any definitely uses my WAN IP.
    - When the TcpListener is not listening (ie. inactive), the same error is thrown by the client.
    - I am running the server on my home computer and am using a router.
    - I have tried configuring the DMZ setting of my router to allow access to my computer.
    - I have also attempted to set up port-forwarding, but I don't know if I've done this correctly.

    My code, if you need it:

    Server

    Code:
    Dim port As Int32 = 3000
    Dim server As TcpListener
    Dim aClient As TcpClient
    
            Try
              server = New TcpListener(IPAddress.Any, port)
            Catch ex As Exception
                MsgBox("Could not initialise server: " & ex.Message)
            End Try
    
            Try
                server.Start()
                lblStatus.Text = "Waiting for connections..."
            Catch ex As Exception
                MsgBox("Could not start server: " & ex.Message)
            End Try
    
    If server.Pending Then
                Try
                    aClient = server.AcceptTcpClient()
                Catch ex As Exception
                    MsgBox("Could not accept connections: " & ex.Message)
                    Exit Sub
                End Try
    Client

    Code:
    Dim client As New TcpClient
             Try
                client.Connect("82.**.***.170", 3000)
                Catch ex As SocketException
                MsgBox(ex.ToString, MsgBoxStyle.OkOnly, "Server Connection Error")
                    Exit Sub
             End Try
    Last edited by Nienna; Feb 1st, 2008 at 07:05 AM.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: VB.Net TCPClient Connection Error

    Is the client running on the same LAN? If it is, you could try connecting to the local IP instead of the external.
    If that doesnt change anything, try a much using a much larger port number on both applications...like 40332.

    Edit: By the way, is that the actual server code? Or a simplified "version" of it?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    25

    Re: VB.Net TCPClient Connection Error

    That is the actual code. The program work when I connect the client to "localhost", but as this is going to be a distributed program, I need to be able to connect from different computers/IP's.

    And yes, that is the actual code.

    I tried the higher port number, but no luck.

    Another point: I used http://www.canyouseeme.org/ to check whether these ports were open, and got a negative.
    Last edited by Nienna; Jan 29th, 2008 at 07:18 PM.

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: VB.Net TCPClient Connection Error

    If it works when you use Localhost, then it must be a router firewall issue. When you're using the external IP, it sends the data outside the local network, going through the router.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    25

    Re: VB.Net TCPClient Connection Error

    Fixed this!

    The problem was that TcpListener can't listen on an external (or WAN) IP. For anyone else who has this problem (with a router):

    You need to

    1. Have your tcpListener listen on your computer's local IP, and a specified port.
    2. Set up your router to forward incoming requests for that port to your computers IP.
    3. Have your TcpClient or Socket connect to your WAN IP, and the same port number.


  6. #6
    Junior Member
    Join Date
    Aug 2015
    Posts
    20

    Re: VB.Net TCPClient Connection Error

    Quote Originally Posted by Nienna View Post
    Fixed this!

    The problem was that TcpListener can't listen on an external (or WAN) IP. For anyone else who has this problem (with a router):

    You need to

    1. Have your tcpListener listen on your computer's local IP, and a specified port.
    2. Set up your router to forward incoming requests for that port to your computers IP.
    3. Have your TcpClient or Socket connect to your WAN IP, and the same port number.

    I know this post is old already, but I'm currently going through the same problem, I followed this tip to try to resolve, but without success so far. I was wondering if anyone had any success with this tip.

    Waiting for answer...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width