[KROYONET] Android 4.2 doesn't connect, 2.2 do

Hello Community,

at the moment i’m writing a mulitplayer app for Android. For this i use Kroyonet. At least i wrote the server application (a simple Java programm running on my PC) and the Android app as the client part. When i try to connect my Nexus 4 (Android 4.2.2) with the server the application crash but if i run the app on a VM (Android 2.2) the client connect to the server. Have someone an idea how to fix this problem?

Thanks

Since it only works on a VM is the nexus 4 on the same network? Is the ip addressing correct?

A VM with 4.2.2 also doesnt work, so i think the nexus is okay. All devices are in the same Network.

is 4.2 above your android supported version? I think this is defined in the android manifest.xml

The supported Version ist 4.2.2, so the highst i can choose. Any other idea?

Maybe you could share your project and I’ll take a look

How can i share it?

I can show you the erro that i get with a 4.2.2 client:


04-27 15:57:10.851: E/AndroidRuntime(11936): FATAL EXCEPTION: main
04-27 15:57:10.851: E/AndroidRuntime(11936): java.lang.RuntimeException: Unable to start activity ComponentInfo{conros.dev.spacerush/cronos.dev.spacerush.SpaceRushStart}: android.os.NetworkOnMainThreadException
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.os.Looper.loop(Looper.java:137)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.ActivityThread.main(ActivityThread.java:5041)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at java.lang.reflect.Method.invokeNative(Native Method)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at java.lang.reflect.Method.invoke(Method.java:511)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at dalvik.system.NativeStart.main(Native Method)
04-27 15:57:10.851: E/AndroidRuntime(11936): Caused by: android.os.NetworkOnMainThreadException
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at libcore.io.IoBridge.connectErrno(IoBridge.java:144)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at libcore.io.IoBridge.connect(IoBridge.java:112)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at java.net.Socket.connect(Socket.java:842)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at java.nio.SocketChannelImpl$SocketAdapter.connect(SocketChannelImpl.java:521)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at com.esotericsoftware.kryonet.TcpConnection.connect(TcpConnection.java:77)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at com.esotericsoftware.kryonet.Client.connect(Client.java:147)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at com.esotericsoftware.kryonet.Client.connect(Client.java:108)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at cronos.dev.spacerush.SpaceRushStart.onCreate(SpaceRushStart.java:87)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.Activity.performCreate(Activity.java:5104)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-27 15:57:10.851: E/AndroidRuntime(11936): 	... 11 more

My 2.2 Client run without this erros. Pls Help

The stack trace indicates you are running the connect operation on the main thread. You’ll need to put that into a background thread so as to not lock up your UI during connect. This is due to StrictMode, added in Android 2.3 but on by default since 3.0. Alternatively, if you really need the connect operation to be on the main thread, then you change the StrictMode policy.

Ohh okay thanks. Is it right that when i but the connection into a background Thread, i can switch between activitys and the connection also hold the line?

The connect thread will only exist as long as the connection is being established. Kryonet maintains its own update thread. As long as your Client is maintained outside of the scope of any specific Activity, there should not be any problem using it from any Activity.

Okay, i swap the client creation, addListener and client start in a background thread. But now when i start the client it connect with the server, the server sends a TCP frame and then the client disconnect. Do you have any idea?