CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    what is valid range of port number to use sockaddr_in?

    hi all,

    i m use sockaddr_in to cocket connection.

    is there any valid range of pot number to establish connection or i can use any port number for connection.

    please help me for this.

    thanks in advance.
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  2. #2
    Join Date
    May 2010
    Posts
    54

    Re: what is valid range of port number to use sockaddr_in?

    Hmmm, I would definitely love to hear some thoughts from everyone too. I guess is, you can not connect to an arbitrary port number. But ideas would still be more benefitial and worthy learning at best. Thank you.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: what is valid range of port number to use sockaddr_in?

    You can use any port number that is not used by other application. Here is a list of known ports: http://en.wikipedia.org/wiki/List_of...P_port_numbers.

    BTW, it should be possible for your application to change the port number, at least have a set of available ports that can be switched between.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    May 2002
    Posts
    1,435

    Re: what is valid range of port number to use sockaddr_in?

    The field is an unsigned short so the range is 0-65535 subject to port availability as suggested in the list above. Note that lists like this are only a very general guideline since the majority of these applications will not be in use on a typical computer and virtually any port (save for a very few common ones) that is available can be used.

    You should also note that a port number is irrelevant if you are creating a client socket as one will be assigned to your connection automatically. It's only important if you are creating a server as you will need to use an available port to listen for incoming connections.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,902

    Re: what is valid range of port number to use sockaddr_in?

    You should only use non-ephemeral ports: http://en.wikipedia.org/wiki/Ephemeral_ports
    >> The IANA suggests 49152 to 65535 as "dynamic and/or private ports."

    gg

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

Featured