kryonet icon indicating copy to clipboard operation
kryonet copied to clipboard

Kryonet disconnects just after connecting

Open ghost opened this issue 12 years ago • 19 comments

From [email protected] on July 07, 2013 19:02:06

What steps will reproduce the problem?

  1. start a server
  2. start client
  3. client keep sendTCP to server
  4. server not send anything to client What is the expected output? What do you see instead? [kryonet] Connection 1 connected: /127.0.0.1 [kryonet] Connection 1 disconnected. in 12 seconds What version of the product are you using? On what operating system? 2.20 Please provide any additional information below. Reason and how to fixed it: if i am keep writing lastWriteTime will bigger than the parameter "time" for method: com.esotericsoftware.kryonet.TcpConnection.needsKeepAlive(long time); so this will case "time - lastWriteTime" < 0 and of course made it < keepAliveMillis. That is why needsKeepAlive() will always return true, and client killed it by itself. i fixed by adding such code in the needsKeepAlive() method and isTimedOut (long time) method, you can see details in attachment. Hope this helpful!! BTW your frame is great! and simple to use!!

Attachment: compare.jpg

Original issue: http://code.google.com/p/kryonet/issues/detail?id=34

ghost avatar Nov 12 '13 16:11 ghost

From twazerty on September 09, 2013 12:36:43

I have the same problem when I only connect via TCP (Server listens on TCP and UDP). When I connect with TCP and UDP in de client everything works ok.

ghost avatar Nov 12 '13 16:11 ghost

From [email protected] on November 06, 2013 01:46:15

I also had this problem.

ghost avatar Nov 12 '13 16:11 ghost

I got the same problem. Is there a solution for this problem?

Kronos87 avatar Nov 21 '13 13:11 Kronos87

I am also having this problem, any solution found? @Kronos87

william-reed avatar Nov 29 '13 23:11 william-reed

See discussion here: https://code.google.com/p/kryonet/issues/detail?id=34 Please continue any further discussion in this thread though.

NathanSweet avatar Dec 27 '13 21:12 NathanSweet

Hey guys, just wanted to add that we're seeing this behavior in the development of an Android app that utilizes Kryonet - when connecting the client only via TCP, it establishes a connection, but any sendTCP calls don't result in the server receiving any data. The server's connected() is not invoked, and the client shortly disconnects after not receiving any response from the server. We are using discoverHost as the basis for the host address the client uses.

If we update the client connect() call to include the UDP port, everything works as expected. The workaround seems to be having the client specify both TCP and UDP ports in connect(), though I do not know the specifics as to what is causing this internally within the Kryonet source (we're using the latest 2.21-all jar in our project).

Just wanted to add our experience, and that the above workaround appears to be working in our case - I hope this helps.

CirceanStudios avatar Jan 22 '14 23:01 CirceanStudios

I experience the same problem and the same solution. You have to specify the UDP and TCP port. Please fix that problem!

ManuelRauber avatar Mar 28 '14 11:03 ManuelRauber

No one shows an executable example and all the KryoNet tests pass, so I assume your code is wrong. Guessing at your problem is usually a waste of time, but probably you start a server that expects both a TCP and UDP connection from a client.

NathanSweet avatar Mar 28 '14 11:03 NathanSweet

I'll prepare an example next week.

ManuelRauber avatar Mar 28 '14 12:03 ManuelRauber

If your server has a TCP and UDP port, your clients must also. You can run a separate server for UDP discovery.

NathanSweet avatar Mar 29 '14 10:03 NathanSweet

Also,when having both ports fail, all of your classes that you register with Kryo, should have an empty constructor inside them, fixed the problem for me. Might be worth putting this into the readme, aswell :) , otherwize this thing is :+1:

makerimages avatar May 10 '14 19:05 makerimages

I'm sorry I forget this issue here.

@NathanSweet Yes, that was the solution! I needed to specify both ports for the clients, too! Thanks :)

ManuelRauber avatar May 23 '14 07:05 ManuelRauber

hit the same issue. my problem was that I registered the UUID class which doesn't provide a public default constructor. replacing it solved the problem for me

breskeby avatar Oct 07 '15 15:10 breskeby

@breskeby Exact same problem here. I'd thought I'd added default constructors to all registered classes, but there was one without. Adding a default constructor fixed it immediately.

ghost avatar Apr 11 '16 21:04 ghost

I agree with @MarkSill, I faced the same problem yesterday and adding ALL default constructors fixed everything! Someone should spread this around.

Isfirs avatar Apr 21 '16 09:04 Isfirs

@Isfirs Same issue, same solution. Public default constructors need to be added to every single one.

adudez96 avatar Jun 23 '18 05:06 adudez96

Sounds like two separate problems:

  1. Not specifying both the same ports on client and server (TCP or TCP+UDP), and
  2. Not providing default constructors.

What error does 2 provide? It should be explicit that a zero arg constructor is needed. Does it fail silently instead? If so, are you using StdInstantiatorStrategy? Using that is not recommended (it creates objects without calling any constructor).

KryoNet is due for an update to the latest Kryo, that may help.

NathanSweet avatar Jun 26 '18 01:06 NathanSweet

My problem was multi-fold...

1.) initially I was using Kotlin data class, which doesn't create empty constructor out of the box

2.) Kotlin also wraps arrays and stuff with its own primitives, so I moved the kryo.register calls (and the commands to send) over to Java

3.) I didn't specify UDP port for the client even though I should have.

4.) I was trying to send TCP message back to the server using the Connection I received in the connected event callback, but apparently instead of that, I was supposed to use client.sendTCP instead of connection.sendTCP.

Zhuinden avatar Jun 10 '19 02:06 Zhuinden

@breskeby Exact same problem here. I'd thought I'd added default constructors to all registered classes, but there was one without. Adding a default constructor fixed it immediately.

Had the same issue. This solved it immediately.

CrashedLife avatar Feb 27 '22 10:02 CrashedLife