Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with setReuseAddress(boolean on) method

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with setReuseAddress(boolean on) method

    I dont undestand well this method.

    Turning on this, Two sockets can use the same port at the same time?

    I thank your helps.


  2. #2
    Junior Member
    Join Date
    Feb 2014
    Location
    Finland
    Posts
    25
    My Mood
    Bored
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Help with setReuseAddress(boolean on) method

    Quote Originally Posted by Luisperseverence View Post
    I dont undestand well this method.

    Turning on this, Two sockets can use the same port at the same time?

    I thank your helps.
    Hi there.

    You should consider posting the javadoc with your question if you want to ask about specific method.

    Here it is:
    setReuseAddress
    public void setReuseAddress(boolean on)
    throws SocketException
    Enable/disable the SO_REUSEADDR socket option.
    When a TCP connection is closed the connection may remain in a timeout state for a period of time after the connection is closed (typically known as the TIME_WAIT state or 2MSL wait state). For applications using a well known socket address or port it may not be possible to bind a socket to the required SocketAddress if there is a connection in the timeout state involving the socket address or port.

    Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) allows the socket to be bound even though a previous connection is in a timeout state.

    When a ServerSocket is created the initial setting of SO_REUSEADDR is not defined. Applications can use getReuseAddress() to determine the initial setting of SO_REUSEADDR.

    The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound()) is not defined.

    Parameters:
    on - whether to enable or disable the socket option
    Throws:
    SocketException - if an error occurs enabling or disabling the SO_RESUEADDR socket option, or the socket is closed.
    Since:
    1.4
    See Also:
    getReuseAddress(), bind(SocketAddress), isBound(), isClosed()
    To answer to your question shortly: Nope.
    As the javadoc states, it enables you to manually set the socket for reuse after the socket is closed.

    Hope that was of some help

  3. The Following User Says Thank You to Wizand For This Useful Post:

    GregBrannon (October 7th, 2014)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help with setReuseAddress(boolean on) method

    You should consider posting the javadoc with your question . . .
    Even better, read the javadoc first and then ask questions to clear up any confusion you have with it.

  5. #4
    Junior Member
    Join Date
    Oct 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with setReuseAddress(boolean on) method

    Hello, you have reason, but I have already seen that before send my question, however, I dont understand it very well.

    When one socket is closed, it remains a little of time more, in order to receive the packets which were on the way, that didnt achieve to arrive, the system doesnt do anything with those packets, only make sure that those ones wont arrive to one open new process that use the same port.

    My question is: ¿setReuseAddress(True) only does that the port closes exactly when the method close() is invoked, and this way, when in that time a new process open this port, the packets which were on the way, will enter to this new process?

    Sorry if I understand totaly bad. Really that I am not the person who ask with no investigate first.
    Last edited by Luisperseverence; October 8th, 2014 at 01:25 AM.
    I am from Peru, therefore I speak spanish, So, sorry if I have some mistakes in my english gramar

Similar Threads

  1. Boolean method help!
    By Scorks in forum Object Oriented Programming
    Replies: 3
    Last Post: April 2nd, 2013, 12:33 PM
  2. I need a little help with a boolean method.
    By bankston13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 30th, 2012, 08:02 PM
  3. Need help with boolean method! =(
    By leao in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 14th, 2010, 10:18 AM
  4. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM
  5. Method returning boolean
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 13th, 2010, 06:45 PM