?
Solved

Re-use socket/port after close() ?

Posted on 2006-06-23
1
Medium Priority
?
687 Views
Last Modified: 2008-03-17
From the Java docs I see the close() method saying:

public void close()
....
Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created.
...

Could someone explain if/why this is true, or is there any way to re-use a port after it has been closed? (i.e., by lowering a time-out value, or setReuseAddress?)

I am not a Java programmer (so please be kind in your answer), but we make use of another language that uses Java libraries for networking and we find that we can only open and close a given connection about 1024 times before a ports unavailable error occurs; even though ALL ports are definitely closed, they are not accessible to the process (netstat shows them in use). As soon as the process is killed, then ports are immediately available for use.

0
Comment
Question by:warba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 16973458
Its just the Socket *instance* that cannot be reused, you can reuse the port.
Just create a new Socket on the port (same way you did for the first one) to open a new connection.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question