Results 1 to 15 of 15

Thread: Tcp ip

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Tcp ip

    Hello,

    I have a (hopefully) small problem/question.
    When I create a TCP server/client it always goes for my network IP.
    How do I get this to listen/read the main ip? (the one outside thats: me -> network -> router/modem -> the internet)

    Thanks in advance

    - Blixa

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Tcp ip

    this will cause it to listen to any ip
    Code:
     listener = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, PortNumber)
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: Tcp ip

    I tried that. How do I figure out on which ip(s) its running?

  4. #4
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Tcp ip

    you can get the clinet ip once you accept the tcp request.

    Code:
    incomingClient = listener.AcceptTcpClient
    ClientIP = incomingClient.Client.RemoteEndPoint.ToString()
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: Tcp ip

    I mean how do I figure out on what IP the server is running at that moment.

  6. #6
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Tcp ip

    try

    Code:
      Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
            MessageBox.Show(h.AddressList.GetValue(0).ToString)
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: Tcp ip

    That seems to work , except it running on IP6 , how can I force IP4?

    Edit:

    I looped through the whole list but it doesnt give the IP it should, seem only to be local IPs.
    I need to connect to an computer at home from work so I need a server to listen the my home's IP.

    any suggestion/help/anything?
    Last edited by Blixa; May 5th, 2010 at 05:21 AM.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Tcp ip

    First up, your computer can, and does, have multiple IP addresses. Secondly, the IP address of your computer is NOT the IP address that people see on the Internet. Your ISP assigns a public IP address to you and that is what others, e.g. web servers, see when they communicate with you. Your router assigns an internal IP address to your computer, which is how multiple computers can share a single internet connection. Your internal IP address is useless if you want to be able to communicate with someone across the internet.

    If you want to communicate with the outside world then you need to know the IP address that your ISP assigned to you. If you have a static IP address then your ISP will have already told you what it is. Whether it's static or dynamic, you should be able to get it from the property pages of your router. If you want to communicate with the outside world then you'll also have to set up port forwarding on your router, which is well beyond the scope of a VB forum. If you have a dynamic IP address then you'll have to let anyone who you want to be able to contact you know what it is first, which is why you should get a static IP address if you want to run servers.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: Tcp ip

    I know my own IP address.
    and I basicly need to forward port 99999 to my pc?

    thanks for the replys so far

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Tcp ip

    Code:
            'yahoo as ip
            Dim ip As System.Net.IPAddress = System.Net.IPAddress.Parse("209.191.122.70")
            'reverse lookup
            Dim he As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(ip)
            'check addresses
            For Each foo In he.AddressList
                If foo.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
                    'ipv4
                    Stop
                ElseIf foo.AddressFamily = Net.Sockets.AddressFamily.InterNetworkV6 Then
                    'ipv6
                    Stop
                End If
            Next
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Tcp ip

    Did your ISP provide you a public IP address, or arrange to have port 99,999 forwarded to your network. I doubt the latter as that is not a legal port number.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: Tcp ip

    I have a public IP, the 99999 was just an example.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Tcp ip

    So then, if someone wants to contact you across the internet then they need to specify your public IP address and a port number. You will have to have forwarded that port number to your computer on your router. Obviously you must set up port forwarding first, then tell the clients what port number to use. The code is exactly the same whether you're communicating across your LAN or over the internet: you specify an IP address and a port number. The difference is who receives and interprets those values: the server itself or the router.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Tcp ip

    Quote Originally Posted by jmcilhinney View Post
    So then, if someone wants to contact you across the internet then they need to specify your public IP address and a port number. You will have to have forwarded that port number to your computer on your router. Obviously you must set up port forwarding first, then tell the clients what port number to use. The code is exactly the same whether you're communicating across your LAN or over the internet: you specify an IP address and a port number. The difference is who receives and interprets those values: the server itself or the router.
    Agreed. If you have this set up properly, the only thing that can go wrong is if the ISP is blocking the port you are trying to use.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: Tcp ip

    ok thanks for the help ganna try to get this working.

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