Kryonet尽快断开客户机1的客户端2连接 [英] Kryonet disconnects client 1 as soon as client 2 connects
问题描述
我和 Kryonet 做1对1的通信工作过和它的工作很好。
I've worked before with Kryonet doing 1-to-1 communication and it worked nicely.
现在我正在做一个更标准的项目,我们将有1服务器和多个客户端连接到它。
Now I'm doing a more 'standard' project where we'll have 1 server and several clients to connect to it.
我遇到的问题是作为标题描述:1进行连接,没有问题的客户端。然后,我问客户端2连接,并立即客户端断开1。不知怎的,服务器不希望保留多个同时连接。
The issue I'm having is as described in the title: client 1 connects, no problem. Then I ask for client 2 to connect and immediately client 1 disconnects. Somehow the server doesn't want to keep more than one simultaneous connection.
我们管理好几次有2相连,那么只要第三连接其他滴。
A couple of times we managed to have 2 connected and then whenever the 3rd connects the other drops.
运行在多种不同的设备ICS的所有+(Galaxy Nexus的,TAB2,SGS3)。
Running on several different devices all ICS+ (galaxy nexus, tab2, SGS3).
在codeS我使用的是非常喜欢的例子:
The codes I'm using are very much like the examples:
服务器端:
server = new Server();
ServiceData.RegisterKryo(server.getKryo());
server.addListener(new MyServerListener());
try {
server.bind(ServiceData.SERVER_PORT_TCP);
server.start();
} catch (IOException e) {
Log.e(TAG, "IOException. Failed to start server. " + e.getMessage());
MyServer.this.stopSelf();
}
然后客户端:
final String ip = intent.getExtras().getString(KEY_SERVER_IP);
listener = new MyClientListener();
client = new Client();
client.start();
ServiceData.RegisterKryo(client.getKryo());
client.addListener(listener);
try {
client.connect(5000, ip, ServiceData.SERVER_PORT_TCP);
} catch (IOException e) {
Log.e(TAG, "IOException. Failed to start client. " + e.getMessage() + "\n");
e.printStackTrace();
MyClient.this.stopSelf();
}
此刻的听众都只是 Log.v(TAG,事情发生);
键,我还启用的所有从Kryonet库日志与 com.esotericsoftware.minlog.Log.set(com.esotericsoftware.minlog.Log.LEVEL_TRACE);
这样我就可以看到,当它连接的,当它断开
the listeners at the moment are just Log.v(TAG, "something happened);
and I've also enabled all the logs from the Kryonet library with com.esotericsoftware.minlog.Log.set(com.esotericsoftware.minlog.Log.LEVEL_TRACE);
so I can see when it's connecting and when it's disconnecting.
我在断开收到两个不同的消息:
I receive two different messages upon disconnection:
DEBUG: [kryonet] Connection 3 timed out.
和
DEBUG: [kryonet] Unable to read TCP from:
真的不知道什么是对这里的任何帮助将AP preciated。
really not sure what's on here and any help will be appreciated.
编辑:
多一点信息:
我已经意识到信息之间:[kryonet]连接3连接:/192.168.0.104
和我的听众收到连接
回调,它采取大约为9秒!非常奇怪的。
edit:
a bit more info:
I've realised that between INFO: [kryonet] Connection 3 connected: /192.168.0.104
and my listener receive the connected
callback, it's taking around 9 seconds! Very odd.
推荐答案
要谁可能进入了同样的问题。
To whom might get into the same issue.
显然,这是一个Android的限制(可能实行,因为它是一个移动设备)
Apparently it's an Android limitation (probably imposed because it's a mobile device)
我刚搬到了服务器
code到正常的Java应用程序的.jar
,让Android的客户端连接到PC,这一切现在工作正常。到现在为止有没有问题连接6台设备进行测试。
I just moved the Server
code to a normal Java application .jar
and let the Android clients connect to the PC and it all works fine now. Until now tested with 6 devices connected with no problems.
这篇关于Kryonet尽快断开客户机1的客户端2连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!