Closed mubbashar closed 6 years ago
From the looks of it, Kyronet Clients must connect to a Kryonet Server in order to function (because of this TCP Registration). I am running into the same problem now trying to connect a client to a NodeJS server.
Running into the same problem. From the side of the server, all seems to connect, but then for some reason the network thread appears to either starve after the timeout setting, or something else goes awry.
The README.md reports that this works under Android, but either something is broken, or we could do with an example...
Was struggling with same issue. On desktop I had server and Android device was a client. This fixed issue for me:
I have the same issue (http://stackoverflow.com/questions/32537154/connecting-socket-io-and-kryonet-connected-but-timed-out-during-tcp-registrati)
Anyone if this would be fixed or not?
I had the same issue, I fixed it by calling client.start()
before connecting:
client.start();
client.connect(...)
KryoNet client can only connect to KryoNet server, due to some initialization packets that need to be transferred, as mentioned. It is not possible to disable this behavior easily and without some digging in the code, because there is a few more (useful) packets that must be handled by both server and client (such as KeepAlive).
To summarize, you can only connect a Kryonet client to a Kryonet server, and you need to call client.start();
before client.connect(...)
. This issue should be closed.
To summarize limitations
Well. I still have this problem. It's working fine between some clients, and not so fine between other.
new Thread(()->{
Client client;
System.out.println("Initializing TV Client");
Log.set(Log.LEVEL_TRACE);
client = new Client();
Kryo kryo = client.getKryo();
kryo.register(RegistrationRequest.class);
try {
client.start();
client.connect(5000, "stress.homeip.net", 6010,6010);
} catch (IOException e) {
System.out.println("Not able to connect to TV Controller");
}
RegistrationRequest registrationRequest = new RegistrationRequest();
registrationRequest.name = "Gunnar";
registrationRequest.mac = "123";
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
}
client.sendTCP(registrationRequest);
while(true)
{}
}).start();
This for example will crash when the registrationrequest is send. And yes, it is registered on the server.
The same here, any news?
@sandro-csimas It seems like i might be some order-problems. I got my TV-client working:
`public class TVClient implements IClient { com.esotericsoftware.kryonet.Client client; Object lock = new Object();
public boolean connected = false;
public TVClient() {
System.out.println("Initializing TV Client");
Log.set(Log.LEVEL_WARN);
client = new Client(256000, 256000);
client.start();
try {
client.connect(5000, "stress.homeip.net", 4450);
connected = true;
} catch (IOException e) {
System.out.println(e.getMessage());
System.out.println("Not able to connect to TV Controller");
}
Kryo kryo = client.getKryo();
kryo.register(TVRequest.class);
kryo.register(StateRequest.class);
client.addListener(new Listener() {
public void received(Connection c, Object object) {
if (object instanceof StateRequest) {
System.out.println("Got state");
StateRequest request = (StateRequest) object;
StateRegister.getRegister().setTVControllerStatus(request.Ready);
}
}
}); }
@Override
public void reconnect(){
try {
System.out.println("Reconnecting in 5 seconds....");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
client.reconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
public void TransmitRequest(IRequest request) {
synchronized (lock) {
client.sendTCP(request);
}
}
} `
There doesn't seem to be an issue here. The OP's problem was that start
was not called before connect
. This issue seems to be resolved. Others later say they get a crash at some point, but don't post the crash. Others say they have a problem, but no executable example code is provided. Please consider posting a new issue with an SSCCE. http://sscce.org/
Even though this is closed, I will leave a quick comment on how I solved my issue. I called start
before connect
and did everything in this thread. My problem, however, ended up being that a config was somehow being read wrong, and setting the timeout to 0. If you set the timeout to 0, you will end up with a Connected, but timed out during TCP registration.
, so you should also double check that.
I am using this library in my android.
socketsingletonObj.start(); Kryo kryo = socketsingletonObj.getKryo(); InetAddress serverAddr = InetAddress.getByName(Helper.serverIpAddress); socketsingletonObj.connect(5000, serverAddr,Helper.serverPort);
why i am getting this error.
while if i use simple socket it works fine like this
InetAddress serverAddr = InetAddress.getByName(Helper.serverIpAddress); socket = new Socket(serverAddr, Helper.serverPort);
it works fine. so should i use simple socket instead of this ?