Re: [xSocket-develop] XSocket not closing underlying OS socket when close() is called
Status: Inactive
Brought to you by:
grro
|
From: Gregor R. <gre...@gm...> - 2010-02-25 07:08:28
|
Hi Erin,
by setting the option SO_REUSEADDR the socket will be released immediately
Map<String, Object> options = new HashMap<String, Object>();
options.put("SO_REUSEADDR", true);
IServer server = new Server(port, options, myHandler);
// ...
Gregor
----- Original Message -----
From: Erin Drummond
Sent: 02/25/10 04:33 AM
To: xso...@li...
Subject: Re: [xSocket-develop] XSocket not closing underlying OS socket when close() is called
Actually I just discovered that sleeping for a bit after the socket
has been closed seems to fix this. Cheers
On Thu, Feb 25, 2010 at 4:30 PM, Erin Drummond <eri...@gm...> wrote:
> Hi,
>
> I am developing an application using xSocket. During the testing, it
> gets shut down and started up again almost instantly. This makes it
> crash with a "BindException: Address already in use".
>
> It appears as though xSocket does not tell the operating system that
> it has finished with the socket when close() is called. If I wait a
> few minutes, the operating system realises the socket isnt being used
> anymore and closes it, which means I can start my application again
> without it throwing an error.
>
> Is there a solution to this? Here is a test case displaying the behaviour:
>
> import org.junit.Test;
> import org.xsocket.connection.IHandler;
> import org.xsocket.connection.Server;
>
> /**
> * Tests rapid creation and destroying of xSocket sockets
> * Will throw an exception on the 2nd or 3rd iteration
> */
> public class XSocketTest implements IHandler {
>
> @Test
> public void test() throws Exception {
> Server s;
> for (int x = 0; x < 500; x++) {
> s = new Server("localhost", 6789, this);
> s.start();
> Thread.sleep(100); //give it some time to initialise
> s.close();
> }
> }
>
> }
>
> I am using Linux 2.6 (in case this is NIO-related)
>
> Cheers,
> Erin
>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
xSocket-develop mailing list
xSo...@li...
https://lists.sourceforge.net/lists/listinfo/xsocket-develop
|