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

java.net.SocketTimeoutException: Connected, but timed out during TCP registration #132

Open
Kuutio opened this issue May 11, 2017 · 2 comments

Comments

@Kuutio
Copy link

Kuutio commented May 11, 2017

server runs fine. client cant connect.
it also says Note: Client#update must be called in a separate thread during connect.
But i got new thread for it ? sorry maybe im idiot :D
oh it crashes after client.connect(9999, ipAddress, tcpPort, 54777);
`public class ConnectClient {

private SomeRequest request;
private SomeResponse response;
private Client client;
public NetworkDATA network;
private String name;

private String ipAddress;
private int tcpPort, udpPort;

private MMORPG game;

public ConnectClient(MMORPG game){
    this(NetworkDATA.SERVER_IP, NetworkDATA.SERVER_TCP_PORT, game);

}
public ConnectClient(String ipAddress, int tcpPort, MMORPG game) {

    client = new Client();

    this.ipAddress = ipAddress;
    this.tcpPort = tcpPort;
    //this.udpPort = udpPort;
    this.game = game;

   network.register(client);

}





public void runClient() {
    Log.w("client started", "started");
    // For consistency, the classes to be sent over the network are
    // registered by the same method for both the client and server.
    client.addListener(new Listener() {
        public void connected(Connection connection) {
            Log.w("connected", "connected");
            NetworkDATA.RegisterName registerName = new NetworkDATA.RegisterName();
            registerName.name = name;
            client.sendTCP(registerName);
        }
    });
    client.start();
    new Thread("Connect") {
        public void run() {
            try {
                Log.w("connecting", "zzz");
                client.connect(9999, ipAddress, tcpPort, 54777); //CRASH HERE
                // Server communication after connection can go here, or in Listener#connected().
            } catch (IOException ex) {
                ex.printStackTrace();
                Log.w("CANT CONNECT", "ERROR");
                System.exit(1);
            }
        }
    }.start();
}

}`

@desertkun
Copy link

How do you run corresponding server? Possibly your tcp ports simple don't match.

@Ivan-Monahhov
Copy link

Ivan-Monahhov commented Jul 11, 2019

This class instance is created on application load. Important note that this is not replicatable with android emulator only with a real phone ( Redmi Go which has Android 8) , but works on CAT S60 which has android 6.0.1

`package org.individual.ivan.geotest;

import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

public class ServerConnection extends Listener
{
Client client;
String ip = "188.166.30.219";
int port = 9001;
MainActivity activity;
public ServerConnection (MainActivity main)
{
activity = main;
this.client = new Client(8192,4096);
client.addListener(this);
client.getKryo().register(Loc.class);
client.start();

    new Thread(){
        public void run()
        {
            try
            {
                client.update(11000);
            }catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }.start();
    try
    {
        client.connect(10000, ip, port);
    }catch (IOException e)
    {
        e.printStackTrace();
        reConnectIn60();
    }
}
public void send(Loc message)
{
    client.sendTCP(message);
}
public void received(Connection c, Object p)
{
    if(p instanceof Loc) {
        Loc loc = (Loc) p;
        activity.updateDistance(loc);
    }
}
private void reConnectIn60()
{
    new Timer().schedule(new TimerTask() {
        @Override
        public void run() {
            new Thread(){
                public void run()
                {
                    try
                    {
                        client.update(11000);
                    }catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                }
            }.start();
            try
            {
                client.connect(10000,ip,port);
            } catch (IOException e)
            {
                reConnectIn60();
                e.printStackTrace();
            }

        }
    }, 60000);
}
public void disconnected(Connection c)
{
    reConnectIn60();
}

}
`

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

No branches or pull requests

3 participants