Connection was forcibly closed by Client

Hi,

I’m having a problem with my client connecting to the server, and i haven’t found any clue searching the posts, so here it goes…

I have a very simple server similar to the HelloUser example. I’m running it from within Eclipse with no problems. Startup log says:

[quote]May 1, 2007 9:16:48 PM com.sun.sgs.impl.kernel.Kernel
INFO: The Kernel is ready, version: 0.9.1-r2129
May 1, 2007 9:16:50 PM com.sun.sgs.impl.kernel.Kernel applicationReady
INFO: FreeTraveller: application is ready
[/quote]
When I try to connect with my (also very simple) client, y get this:

[quote]ay 1, 2007 9:16:57 PM com.sun.sgs.impl.service.session.ClientSessionImpl$Listener exceptionThrown
WARNING: Handler.exceptionThrown handle:com.sun.sgs.impl.io.SocketConnection@95fd19
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(Unknown Source)
at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(Unknown Source)
at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$4(Unknown Source)
at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(Unknown Source)
at org.apache.mina.util.NamePreservingRunnable.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
[/quote]
The client just does this to connect:

The server is running at localhost, port 1139 (but the connection is received and then shutdown by the client, so that info is ok). OS is Windows XP. I suspect either some kind of operating system/permission/security problem (but i even shut down the firewall to test this), or maybe some Eclipse thing with two apps. running inside trying to connect to each other (I’ll try running some - or both - outside Eclipse). Could someone hint me on where could I look for the problem?

Thanks

Is that exception on the client or the server?

That makes a big difference.

My wild guess at the moment is that the exception is on the client, and the cause is that you are returning NULL for your session listener from the loggedIn() callback on the server side.

This indicates a rejection of the user by the server app code and it forceably disconnects the client.

This should be in the both the API docs and the tutorial…

It’s on the client. I don’t have the code right now, but I’m pretty sure I created a ClientSessionListener (actually, a class that inherits from it) that is returned in the loggedIn. It’s also being added to a List, so I think if it was null I should get an NPE before even returning it. I will check my code again, and try to run the examples too.
Thanks.

Make sure to enable logging. (Look in the logging.properties file for directions or in the server tutorial.)

You may be exceptioning on the server and not knowing it.

Ok, i’ve got it. Thing is, after calling client.login(connectProps), my client application’s main method ended. I assumed that the client libraries would wait for a response, so I had some loop code at the loggedIn() method just waiting to be invoked. But it seems the application ended before the code was even invoked.
As the examples are Swing from the client side, and Swing has it’s own thread maintaining the application running, the problem could not be noticed.

Now I have some thread waiting for the connection. Anyway I still have something strange happening with the threads in the client side, I think I’m still not getting exactly how this (asynchronous?) communication from the client should be handled, but I know where to look at. :slight_smile:

Yeah, communication in the client side Java API comes in asynchronously. A common Java mechanism though counter-intuitive I’d admit for most experienced game programmers.

In bunny hunters I just queued the incoming packet and then handled the queue in my main game loop.

Of course, if your client app is Swing, that implies an event driven rather then loop driven client, yes?

Anyway anything I can help with please feel free to ask.