Solved

Re-use socket/port after close() ?

Posted on 2006-06-23
1
681 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
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 250 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 82
servlet example issue 6 38
Why my table column Id is not passed to java object? 4 38
Chrome and Firefox Java 5 23
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now