Open Kuutio opened 7 years ago
How do you run corresponding server? Possibly your tcp ports simple don't match.
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();
}
} `
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 {
}`