get local port

Discussion in 'Java' started by jiefeng Xu, Sep 26, 2003.

  1. jiefeng Xu

    jiefeng Xu Guest

    I want to know if there is a way in Java to retrieve the local port. A
    lot of the methods I find need to provide with the IP or port
    information. I can find the local hostname, but not the port. Can
    anyone give a hand on this. I appreciate the help. Thanks.
     
    jiefeng Xu, Sep 26, 2003
    #1
    1. Advertising

  2. jiefeng Xu

    Roedy Green Guest

    On 26 Sep 2003 10:29:09 -0700, (jiefeng Xu) wrote or
    quoted :

    >I want to know if there is a way in Java to retrieve the local port. A
    >lot of the methods I find need to provide with the IP or port
    >information. I can find the local hostname, but not the port. Can
    >anyone give a hand on this. I appreciate the help. Thanks.


    That question has many answers. The port number depends on the
    protocol. See http://mindprod.com/jgloss/port.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Sep 26, 2003
    #2
    1. Advertising

  3. On 26 Sep 2003 10:29:09 -0700, jiefeng Xu wrote:
    > I want to know if there is a way in Java to retrieve the local port.
    > A lot of the methods I find need to provide with the IP or port
    > information. I can find the local hostname, but not the port. Can
    > anyone give a hand on this. I appreciate the help. Thanks.


    From your description it sounds like you're asking for something that
    might be a static attribute of the host computer itself, but that's
    not what port numbers are.

    Every open Socket and ServerSocket has a (possibly unique) local port
    number, and every connected Socket has a remote port number as well.
    Consult the API documentation for these two classes to see how to get
    the information.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Sep 26, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John T. Goodman

    Overhead of 4-port over 2-port SRAM

    John T. Goodman, Jan 25, 2005, in forum: VHDL
    Replies:
    0
    Views:
    661
    John T. Goodman
    Jan 25, 2005
  2. Sean Wolfe
    Replies:
    1
    Views:
    2,318
    Joerg Jooss
    Apr 28, 2005
  3. =?Utf-8?B?WVNVVA==?=

    Access local port or Running local exe file

    =?Utf-8?B?WVNVVA==?=, Jan 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    542
    =?Utf-8?B?WVNVVA==?=
    Jan 14, 2006
  4. andres
    Replies:
    1
    Views:
    5,340
    dgoyani
    Oct 23, 2007
  5. Replies:
    1
    Views:
    674
    Toni Erdmann
    Mar 2, 2005
Loading...

Share This Page