Results 1 to 2 of 2

Thread: TcpListener and IPAddress.Any

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    25

    TcpListener and IPAddress.Any

    Hey guys,

    I am currently living in a student house with 5 computers connected to a wireless router.

    I was wondering, then, what IP address the IPAddress.Any method would return in VB.Net, as I am trying to set up a TcpListener using it.

    Here is what I am trying to do: I want the TcpListener to start listening on the host computer port 3001 as soon as my VS programme starts. As far as I am aware, a TcpListener can only run on an internal IP, but I am not 100% sure how to get the internal IP of the host computer as I don't want to hard-code it so that the application will work on any computer that it is run on.

    Is IPAddress.Any the right thing to use? If not, what is a better way of doing this?

    Thanks,
    K

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

    Re: TcpListener and IPAddress.Any

    The TcpListener can only listen on local IPs. Take a look at the documentation for that particual constructor overload, and you'll see that this is said about using IPAddress.Any:

    If you do not care which local address is assigned, specify IPAddress.Any for the localaddr parameter, and the underlying service provider will assign the most appropriate network address. This might help simplify your application if you have multiple network interfaces.
    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)

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