Re: "java.net.BindException: Address already in use: connect" ? ?



On 28 Jul 2005 02:54:18 -0700, cmk128@xxxxxxxxxxx wrote:
> My java slcient connect to the server may many time by socket. My
> problem is: "socket.close()" doesn't release the local port. After
> running "new Socket()" many time, it will get "java.net.BindException:
> Address already in use: connect" exception.
> If i specify the local port to be use by "new
> Socket("localhoist",18001,InetAddress.getLocalHost(),18002)", it get
> the same error, because "socket.close()" doesn't release the port.

It is normal for the address to remain in use for a few minutes after
closing the Socket.

It is however extremely unusual to care which port number is chosen by
the client. If you don't specify a client port number, the system will
simply choose an available one.

If you really do need to specify the client port number, you can also
use setReuseAddress() and the address will become available again
immediately after you close the Socket.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
.



Relevant Pages

  • Re: Bug with instanceName property?
    ... If you specify a portnumber attempt to connect using port number. ... I installed SQL Server 2005 on a ... > you get a more efficient connection since it doesn't need to connect to ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: To allow inbound traffic from a specific ip
    ... create a new protocol for ... specify in the Primary connection in the Protocol field TCP ... TCP, and the direction as inbound, and the port range that you seen, note ...
    (microsoft.public.isa.configuration)
  • Re: Why does printk helps PCMCIA card to initialise?
    ... and can also specify how many IO address lines they ... restriction for a card; if it only decodes 3 lines, ... port boundary. ... are specified that the meaning is complicated. ...
    (Linux-Kernel)
  • Re: Passive mode FTP under Solaris 10?
    ... I've come to understand that I need to specify a range of high ports ... There seems to be alternate ftp server software that's easy to ... When any control connection matching ... Allows control of the TCP port numbers which may be used ...
    (comp.unix.solaris)
  • Re: BTS2004 Dynamic Send Port with XmlDocument and SOAP
    ... The send port will need an assembly and class specified as context ... will be used to call the web service. ... This gives the adapter enough information to create the proxy ... specify an Assembly in my message. ...
    (microsoft.public.biztalk.general)