Solved

Re-use socket/port after close() ?

Posted on 2006-06-23
1
679 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
endX challenge 2 50
pairs challenge 5 45
Running Jira on Raspberry PI 2? 3 137
Java Message handling in Service Layer 3 37
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

759 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

21 Experts available now in Live!

Get 1:1 Help Now