0
\$\begingroup\$

The dedicated server would be a lobby where all the players connect and find matches. Once a match is found the server hooks to two players and sends them off on a p2p network. Once the match is over, the players would reconnect to the lobby to find a new match. Is this a viable approach? Or does WiFi not handle P2P under any wide band situations (unlike Wifi direct (very local) or bluetooth (extremely close))?

As far as trying it out, I attempted to record an ip address and port number at the server and send that information in a packet to my other mobile device. Once the client A "had" client b's address + port, and vise versa, I assumed I could send messages, but that didn't really seem to work.

I'm using java NIO, so it would look something like this (pseudo):

Client A creates a datagram channel and set it to non blocking
Send connection request message to the server using the datagram channels send function
Server receives request and routes the address to the first available client, Client B (already connected and waiting)
Server sends Client A's address, to Client B's address and vise versa
Each client rebinds there datagram channel to the new address
Client A and B should be able to send messages to each other (this though did not seem to work)
\$\endgroup\$
2
  • 1
    \$\begingroup\$ It appears you are trying to do a NAT punch through/UDP hole punching. I wish it was as easy to do, but I never managed to get it to work reliably. UPnP is much better if it works for you. Aside from that, I'd say go full WebRTC if you can help it. Edit: or perhaps a third party solution works for you, such as discord. \$\endgroup\$
    – Theraot
    Oct 10, 2021 at 6:44
  • \$\begingroup\$ yeah now that I'm reading your response, that's exactly what I was trying to do. In my case I have an emulated device and my own. Because my real device's ip was being "masked" for lack of a better term, I wasn't able to send messages to it. But to the NAT address. UPnP seems to have its own issues as well but I may look into defending against pinkslipbot and other similar attacks if I have time. Thanks :) \$\endgroup\$ Oct 10, 2021 at 15:04

1 Answer 1

0
\$\begingroup\$

Instead of trying to connect the two players directly, you should use a relay to mediate the connection between the two players. That way, you won't run into NATing issues because the data is being transmitted through a 3rd party.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .