Kryonet - connecting from the same IP address (different LAN addresses)

Let’s say that I have my TCP server in Germany.

When I try to connect from two mobile phones from Poland in the same LAN network (they have different ip’s here):

192.168.1.8 and 192.168.1.14

It disconnects previous device. They both have the same global address, and I don’t know how this is happening, cause I store only connections, not the InetAddresses:

public ArrayList<Connection> connectionsList = new ArrayList<Connection>();

The best thing is that when I open two emulators in the same PC, they work + I can even add one mobile phone O.o.

Btw. I have both UDP and TCP ports included in Server and Client’s constructors.

This is so strange that when I open emulators from the SAME IP ADDRESS in LAN they can work, when I try to open two phones it fails.

Is there someone who could point a solution?

I have similar problems with many multiplayer games (Cannot join the same server with two clients that are behind the same router, for example cs:go)
It is probably related to the router’s port forwarding; You need to map the port you’re using internally to a different outgoing port for the second device behind the router.
I don’t know if it works but you could try it out :point:

it would then looks like this:
[…] is the port

  • kryoClientNR1[80]->router remaps to [80]->WAN[80]->router remaps to [80]->kryoServer[80]
  • kryoClientNR2[80]->router remaps to [81]->WAN[81]->router remaps to [80]->kryoServer[80]

This should help the routers recognize the two devices as separate connections, but i don’t know if it works…

Thanks for your reply!

I think that this is not a good solution, cause let’s see - every user of my app would have to change their router’s config.
We need to wait for someone professional - cause there are games like for ex. Hearthstone and we can open 100 connections behind one router without making changes in config - and it works.

I don’t have this problem anywhere, but here - on my client<>server yes.

The worst thing is that I don’t understand HOW it’s possible that two android emulators are working from the SAME PC.

As long as your server is not behind a NAT (Network Address Translator) then it just works, simply said.
I suspect that both your server and your client are behind NATs/routers, in which case there really is no easy solution.
There are solutions but they vary wildly based on the kind of NATs that the peers are behind and they mostly require a third party not behind a NAT.
I don’t know Hearthstone, and your network setup for it, but I suspect a client of that game connects against an official server with an official public IP address.
If that’s the case, then we are at what I said in the first sentence.

Thank you for your reply!

By saying Hearthstone I meant every popular game, like Diablo, WoW, League of Legends.

I don’t need to change my router’s config to be able to play with my two brothers from one LAN on their global servers.

My own server is placed on a dedicated machine with allowed UDP & TCP ports on iptables and Ubuntu Firewall.

This is strange…

I meant that - my machine has a public address - visible and open from anywhere.

Every popular game’s servers are running with public IP addresses and therefore (simply speaking) no clients needs to change their router configuration to play publicly hosted games.

If by “my machine” you mean your server, then in this case your application is likely to have a bug somewhere, or you did something to iptables. :slight_smile:
Client-side NAT will just function properly and every client behind that NAT will seem like a different client to your server, because of different source ports (although with identical IP addresses).

So you are 100% sure, that my bug is server-side, right?

I’ll try to enable debug logs, maybe I’ll get something more.

I’d advise you to do a tcpdump on the server side, to see what really happens, and look at it with Wireshark.
Those two tools come in very handy when trying to solve network problems.
Doing a tcpdump (care to record whole packets!):


sudo tcpdump -s 0 -i any -w dumpfile.pcap

Abort with Ctrl+C if you think you collected enough data.

Okay, I’ve discovered something.

Changed some server code. I’m trying to implement 1v1 battles:
Queue has max one player
If it reaches two players it creates a new GameRoom and pass the players to it and there it starts to listen.
Queue is empty etc…

The problem wasn’t with IP addresses (maybe it was O.o). Now I can mix the devices - even two mobile phones + one emulator. I’ll try to figure out what may cause this…

With tcpdump/Wireshark you can also see if and who (client or server) resets a connection, since you said that one client is being disconnected when another connects.
Like I said, this all sounds very much like an error in the server application and even perhaps in the client, if the client reacts strangely to some messages sent by the server.
It seems that the error should really be found within your own application code, and not within Kryo, for instance.

Okay - found it - what a strange thing…

Two emulators were crashing. I went to my colleague, to my neighbour, brother, took their phones:

Connected 5 devices - everything running smoothly.
Added one emulator - still OK
Added second - crash.

Two emulators on the same PC == death.