jack0088 wrote: ↑
Fri Jun 30, 2017 7:41 pm
I'm facing the similar problem.
I want several clients to have a separate sqlite database, but keep all of the clients in sync. I use UDP for this and on the local network it works. But it would be better if I could sync from anywhere I have an internet connection. So, then I had the idea of having a remote server with open port 42000.
The remote server would basically work as a share station ("lobby") for UDP messages. Each client can send some message to the remote server and also at the same time listen for others messages and pick up the ones it needs.
But frankly that didn't work. It seems like the message is send, but I can not listen to the remote server. If I try to see what my :getsockname() is .. it's the local IP of my mashine instead of the remote servers ip, although I was bound to it.
Turn's out I maybe need to use some NAT hole punching technique to connect the wires... Would you share your code with me please?
, so I get an idea what to do? I basically understand the concept, but don't know where to start. Do I need some script to run on the remote server S which connects Client A & Client B?
I'm quite rusty on this subject, not sure if I can be helpful. But from what I remember, the idea is:
=> On your public server (you must be sure than connecting to this server is not an issue, that its IP is public and not behind a NAT), you need a script that makes 3 things:
- When a client connects to it, send back to the client its public IP (I've been using socket for it, not enet, as we need a TCP connection to retrieve the IP, we can't get it from enet if I remember correctly).
- Now that the the client is aware of its private and public IPs, reconnect to the server using UDP (via enet in my case) to create a hole in the port I need and to ask to the server the address of the machine(s) you want to connect to (getting both private and public IPs).
- Notify the other machine(s) that a new client is here and wants to connect, and provide its IPs.
=> And now the idea to be sure to punch a hole for the UDP connection is to try to create a connection from all sides with both the public and private IPs, and as soon as one connection succeed, you can discard the others.
But as said before, if the idea is just to connect to a server and not create a peer-to-peer connection between clients behind NATs, hole punching is useless for you, as to make it work you need in all cases a server well configured to accept UDP connections in the port you'll use.