Re: [xSocket-develop] ClosedConnectionException
Status: Inactive
Brought to you by:
grro
|
From: Gregor R. <gre...@go...> - 2008-05-03 11:45:42
|
Hi Mohamad,
by default the connection and idle timeout of xSocket connections is ~ 70
years. To verify that xSocket doesn't close the connection caused by a
timeout, you can implement the ITimout handler interface. The methods of the
timeout handler will be called if a timout occurs.
Additional you can activate xSocket's log to see what happens under the
hood.
Please see the example enclosed
Gregor
public static void main(String[] args) throws IOException {
Logger logger = Logger.getLogger("org.xsocket.stream");
logger.setLevel(Level.FINE);
ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(Level.FINE);
logger.addHandler(ch);
IMultithreadedServer srv = new MultithreadedServer(new Handler());
// srv.setIdleTimeoutSec(3);
srv.run();
}
private static final class Handler implements IDataHandler,
ITimeoutHandler {
@Override
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException {
connection.write(connection.readAvailable());
return true;
}
@Override
public boolean onConnectionTimeout(INonBlockingConnection
connection) throws IOException {
System.out.println("connection timeout occured (connection
timeout=" + connection.getConnectionTimeoutSec() + ")");
return false; // returning false causes that the connection
will be closed
}
@Override
public boolean onIdleTimeout(INonBlockingConnection connection)
throws IOException {
System.out.println("idle timeout occured (idle timeout=" +
connection.getIdleTimeoutSec() + ")");
return false; // returning false causes that the connection
will be closed
}
}
2008/5/3 Mohamad Azri Bin Azhar <az...@gm...>:
> Hi there,
>
> I'm using xSocket 1.2.1 MultithreadedServer to listen for HTTP POST
> request. Upon receiving the request, I'd do something with the data
> which takes like 1 to 3 seconds and response back to the client.
>
> Basically, inside my onData() handler, I'd have something like:
>
> connection.readByteBufferByDelimiter(delimeter);
> //do something, and then:
> connection.write(someData);
>
> However, every an hour or so it won't be able to write the response back
> and get the following exception:
>
> org.xsocket.ClosedConnectionException: connection
> 7c292b5b.119a45810b8.4d6a25b2.s.12074 is already closed
> at org.xsocket.stream.Connection.write(Connection.java:667)
> at org.xsocket.stream.Connection.write(Connection.java:582)
> at
>
> org.xsocket.stream.NonBlockingConnection.onDataEvent(NonBlockingConnection.java:757)
> .......
>
> My question is, does the connection here is closed by xSocket? If so,
> any idea to solve this?
>
> (btw, the client is an Axis client which simply post the request to my
> xSocket server)
>
> Thank you.
>
> Regards,
> Azri.
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
>
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
|