Hi people, so I once made a simple multiplayer game, but the architecture was pure client-server. Now I'm trying my hands on P2P using a central server for matchmaking only, but I hit a brick wall here.
So here's what the server does:
- Start udp socket, listening at [any] interface on port 3232
- Whenever client connects:
- Add this [client] to [list of connected clients]
- Send this [client] the following info:
- his public ip+port (as seen from the server)
- all his peers (connected clients so far)'s public ip+port
- And every 200 ms, do the following things to connected clients:
- keep sending him ping message, and receive pong message back (to keep the line open and measure latency)
And for the client, it's also simple:
- start udp socket, connect to server
- receive all kinds of message from server
- when receiving a list of peers, do this:
- send a hello message to every peer's public ip+port
- keep doing this every 200ms
Thing is, the packet to peer's public ip+port never arrives at the other end. I even tested this @ localhost, still no luck, wtf. I started the Server, then the clients, all communications between server to clients works really well. But client to client packet just doesn't get through. I also tested it using netcat (try to send garbage to the client's ip+port as seen from server), still nothing gets passed. I log the client's receive function heavily, but still only packets from server gets received. What did I do wrong? I thought that's how UDP Hole punch works?
I understand that not all kinds of network connection supports UDP hole punch, and I'm using 4G Broadband USB Modem at home. But the thing is Torrenting just works! so I thought the UDP hole punch should work. Even if it can't work because of my network, it must work @ localhost, amirite?