Connection is closed ?

439 views
Skip to first unread message

Samuel Landon

unread,
May 9, 2012, 6:11:53 AM5/9/12
to kryone...@googlegroups.com
Hi everybody.
I'm from France and i'm trying to write a client/server application for a card exchange game using Android OS.
I've found your work, and I'm trying to use it for my projet.

I've tested the Position example. It only worked once perfectly.
Then, I can still start the PositionServer, but as soon as I try to send the login in the PositionClient, I get the following error :

java.net.UnknownHostException: joe
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:867)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1246)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1197)
    at java.net.InetAddress.getAllByName(InetAddress.java:1128)
    at java.net.InetAddress.getAllByName(InetAddress.java:1064)
    at java.net.InetAddress.getByName(InetAddress.java:1014)
    at com.esotericsoftware.kryonet.Client.connect(Client.java:115)
    at com.esotericsoftware.kryonet.examples.position.PositionClient.<init>(PositionClient.java:74)
    at com.esotericsoftware.kryonet.examples.position.PositionClient.main(PositionClient.java:160)
00:11 DEBUG: [kryonet] Unable to send TCP with connection: Connection -1
java.net.SocketException: Connection is closed.
    at com.esotericsoftware.kryonet.TcpConnection.send(TcpConnection.java:186)
    at com.esotericsoftware.kryonet.Connection.sendTCP(Connection.java:68)
    at com.esotericsoftware.kryonet.examples.position.PositionClient.<init>(PositionClient.java:83)
    at com.esotericsoftware.kryonet.examples.position.PositionClient.main(PositionClient.java:160)

However, I have not made any changes anywhere in the code.

Could you help me with this ? Is it a port occupied kind of error ?
Thanks.

Samuel Landon

unread,
May 10, 2012, 4:44:31 AM5/10/12
to kryone...@googlegroups.com
Forget about this question, I've figured it out. I was too impatient, so I put a name in the field host... of course it couldn't work.
So, this is okay now.
But, my real problem is the following : how to make this work on android ?
Do you have an exemple of a simple client/server using kryo, sending and receiving objets, on Android ?
I've tried to adapt the Position example, but it crashes everytime, and I don't know why (it seems it can't find the Client class, which makes no sense because in the example you provided it worked perfectly).

Thanks for any help.

Nate

unread,
May 10, 2012, 5:21:25 PM5/10/12
to kryone...@googlegroups.com
It sounds like you just need to get your project setup so Android can find the JARs. Put ALL the KryoNet JARs on your Android project as dependencies. Start simple, write an Android app that creates a Client and System.out.printlns any object received. Make sure you specify the server host properly, localhost will not work. Expand on your app from there.

-Nate


--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users

Samuel Landon

unread,
May 11, 2012, 4:45:21 AM5/11/12
to kryone...@googlegroups.com
Thanks Nate for your answer.
In fact, there is no error in the code. So, i believe it finds the jars perfectly.
It crashes on the connection. So, the problem is probably what you said about the host. Localhost can't work, because it tries to connect to itself (the emulator, the device), and not to the server on my computer.
How can I change this ?
Should I install a tomcat server with a fixed IP to test it ? Is there an other way, simplier way to test it ?


Le jeudi 10 mai 2012 23:21:25 UTC+2, Nate a écrit :
It sounds like you just need to get your project setup so Android can find the JARs. Put ALL the KryoNet JARs on your Android project as dependencies. Start simple, write an Android app that creates a Client and System.out.printlns any object received. Make sure you specify the server host properly, localhost will not work. Expand on your app from there.

-Nate


Samuel Landon

unread,
May 11, 2012, 6:09:45 AM5/11/12
to kryone...@googlegroups.com
Maybe you're right. I get the same error each time :
05-11 12:04:05.560: E/dalvikvm(506): Could not find class 'com.esotericsoftware.kryonet.Client', referenced from method slandon.android.TestClientAndro1Activity.onCreate
My app is very simple, I only put a new Client(); in the OnCreate method.

Where should I put the jar file ? It appears correctly in Referenced Libraries. Or, I can put it in the file system, but it still crashes.
There is no error in the code when I do the import " import com.esotericsoftware.kryonet.Client; "
That's why I don't get it !
I have selected the kryonet-1.04-all.jar, is that correct ?

Samuel Landon

unread,
May 11, 2012, 7:51:29 AM5/11/12
to kryone...@googlegroups.com
Okay, now I've sorted out the "Class not found problem".
http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
It was an ADT problem. The Dependencies change in the version 17 version. How could I know ?
This is OK but the program still crashes for another problem.

I made the Client as simple as I could. Here is my code :

package slandon.android;

import android.app.Activity;
import android.os.Bundle;

import com.esotericsoftware.kryonet.Client;

public class TestClientAndro1Activity extends Activity {
   
    Client client;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        client = new Client();
        client.start();
       
    }
}

The error I get is :

05-11 13:40:14.578: W/dalvikvm(756): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
05-11 13:40:14.578: E/AndroidRuntime(756): Uncaught handler: thread Client exiting due to uncaught exception
05-11 13:40:14.588: E/AndroidRuntime(756): java.lang.NullPointerException
05-11 13:40:14.588: E/AndroidRuntime(756):     at org.apache.harmony.nio.internal.SelectorImpl.prepareChannels(SelectorImpl.java:223)
05-11 13:40:14.588: E/AndroidRuntime(756):     at org.apache.harmony.nio.internal.SelectorImpl.selectInternal(SelectorImpl.java:191)
05-11 13:40:14.588: E/AndroidRuntime(756):     at org.apache.harmony.nio.internal.SelectorImpl.select(SelectorImpl.java:167)
05-11 13:40:14.588: E/AndroidRuntime(756):     at com.esotericsoftware.kryonet.Client.update(Client.java:240)
05-11 13:40:14.588: E/AndroidRuntime(756):     at com.esotericsoftware.kryonet.Client.run(Client.java:332)
05-11 13:40:14.588: E/AndroidRuntime(756):     at java.lang.Thread.run(Thread.java:1096)
05-11 13:40:14.598: I/dalvikvm(756): threadid=7: reacting to signal 3
05-11 13:40:14.618: I/dalvikvm(756): Wrote stack trace to '/data/anr/traces.txt'
05-11 13:40:22.189: I/Process(756): Sending signal. PID: 756 SIG: 9

Have you got an idea ?

James Hooker

unread,
May 11, 2012, 8:26:31 AM5/11/12
to kryone...@googlegroups.com
Hi Samuel,

I'd try adding a listener before starting the client, like this:

Client client;
client = new Client();
client.addListener(new Listener(){
public void connected (Connection connection) {
Log.e("Kryonet","connected");
}
});
client.start();

I've just created a new test project with the above code, and it worked just fine. Be sure you're using the kryonet-all jar. Try placing it into a 'libs' directory in your project workspace AND including it in the build path.

Hope this helps.

Kind regards,
James H



Samuel Landon

unread,
May 11, 2012, 10:59:38 AM5/11/12
to kryone...@googlegroups.com
James,

Here is what I've done, using your code in an Activity Class :


package slandon.android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;



public class TestClientAndro1Activity extends Activity {
   
    //Client client;

   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Client client;
        client = new Client();
        client.addListener(new Listener(){

            public void connected (Connection connection) {

                Log.e("Kryonet","connected");

            }

        });
        client.start();
       
    }
}

The jar file, is the right one. It appears in the Referenced Librairies folder and in the Android Dependencies folder.
But I get the same error (uncaught exception - null pointer exception), when it executes.

Could you send me your full test file (Activity class) so I can try to find where I made a mistake ?

Nate

unread,
May 11, 2012, 4:38:30 PM5/11/12
to kryone...@googlegroups.com
Your stacktrace shows:

at org.apache.harmony.nio.internal.SelectorImpl.select(SelectorImpl.java:167)
at com.esotericsoftware.kryonet.Client.update(Client.java:240)

The current KryoNet code doesn't call select() on line 240 of Client. Possibly you aren't using the latest code?

Beyond that, getting an NPE in the bowels of the Harmony NIO stuff is not good. Harmony has been broken in the past...
http://www.badlogicgames.com/wordpress/?p=1231
What version of Android are you running? What device?

Your code is so simple at this point I would guess it is either using the wrong KryoNet or something is terribly, terribly wrong.

-Nate


Samuel Landon

unread,
May 11, 2012, 6:13:26 PM5/11/12
to kryone...@googlegroups.com
I'm using the last file I found on the download page : 1.04 (Feb 2011). I've never downloaded the previous versions.
I'm working on Android 2.1 (API level 7). I work on a simple emulator, no fancy device.
I use Eclipse as IDE.
I work on Linux Mint 11 - Gnome 2.32

Nate

unread,
May 11, 2012, 8:14:22 PM5/11/12
to kryone...@googlegroups.com
You could try the KryoNet from SVN. I need to do a release, to 2.0. Unfortunately the emulator is known for being crappy.

-Nate


--

Samuel Landon

unread,
May 12, 2012, 7:56:24 AM5/12/12
to kryone...@googlegroups.com
I've got the SVN trunk access, but how can I find the one-jar file in the last version ? Should I create it myself ? (I can do that, but I don't want to miss anything).
Would you have a direct link ?

Nate

unread,
May 12, 2012, 3:51:07 PM5/12/12
to kryone...@googlegroups.com
When you run from SVN you add the kryo project as a dependency to your Android project, no JAR.

I just did a release for Kryo and KryoNet, so you can download the latest KryoNet zip (2.08) and use the JARs there. I recommend using this one:
jars/debug/onejar/kryonet-debug-2.08-all.jar
This JAR lets you enable debug logging. When you ship your app use:
jars/production/onejar/kryonet-2.08-all.jar

-Nate


On Sat, May 12, 2012 at 4:56 AM, Samuel Landon <slandr...@gmail.com> wrote:
I've got the SVN trunk access, but how can I find the one-jar file in the last version ? Should I create it myself ? (I can do that, but I don't want to miss anything).
Would you have a direct link ?
Reply all
Reply to author
Forward
0 new messages