Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Re-use socket/port after close() ?

Posted on 2006-06-23
1
Medium Priority
?
694 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses

636 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