Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kryonet disconnects just after connecting #35

Open
ghost opened this issue Nov 12, 2013 · 19 comments
Open

Kryonet disconnects just after connecting #35

ghost opened this issue Nov 12, 2013 · 19 comments

Comments

@ghost
Copy link

ghost commented Nov 12, 2013

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
Copy link
Author

ghost commented Nov 12, 2013

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
Copy link
Author

ghost commented Nov 12, 2013

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

I also had this problem.

@Kronos87
Copy link

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

@william-reed
Copy link

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

@NathanSweet
Copy link
Member

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

@CirceanStudios
Copy link

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.

@ManuelRauber
Copy link

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

@NathanSweet
Copy link
Member

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.

@ManuelRauber
Copy link

I'll prepare an example next week.

@NathanSweet
Copy link
Member

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

@makerimages
Copy link

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 👍

@ManuelRauber
Copy link

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 :)

@breskeby
Copy link

breskeby commented Oct 7, 2015

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

@ghost
Copy link

ghost commented Apr 11, 2016

@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.

@Isfirs
Copy link

Isfirs commented Apr 21, 2016

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

@adudez96
Copy link

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

@NathanSweet
Copy link
Member

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.

@Zhuinden
Copy link

Zhuinden commented Jun 10, 2019

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.

@ghost
Copy link

ghost commented Feb 27, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

10 participants