UDP hole punching

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

UDP hole punching

Post by Fenrir »

Hi all,

Anyone knows a LUA library to do UDP hole punching ?

Thanks!
Cheers,
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: UDP hole punching

Post by Roland_Yonaba »

I never heard about/came accross anything linke this.
Maybe you should ask on lua-l mailing list.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: UDP hole punching

Post by Fenrir »

Thanks for your reply, I found nothing in the mailing list archive and I'm too lazy to subscibe, I think I'll just go try to implement something myself.

Cheers,
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: UDP hole punching

Post by Fenrir »

Hi guys,

Just for the record I managed to get something working following this paper:
http://www.brynosaurus.com/pub/net/p2pnat/

I've got a "lobby" server running with a simple LUA script returning to each clients public and private IPs of the server (and vice-versa for the server). And on the LOVE side I'm using Enet to try to establish the connection to both IPs, one important thing is to try to connect from the client AND from the server to be sure to "punch" the hole on both side, then I only use the first connection which succeed and discard the other one.

Cheers,

PS: BTW, Enet totally rocks, thanks for adding it to LOVE!
User avatar
jack0088
Prole
Posts: 33
Joined: Fri Mar 22, 2013 4:59 am

Re: UDP hole punching

Post by jack0088 »

Hey @Fenrir

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?
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: UDP hole punching

Post by zorg »

jack0088 wrote: Fri Jun 30, 2017 7:41 pm ...
I'd consider telling you the same as what i tell anyone in this situation, but to be frank, this feels like one of the more reasonable reasons for necroing a 3 year old thread... we'll see.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
jack0088
Prole
Posts: 33
Joined: Fri Mar 22, 2013 4:59 am

Re: UDP hole punching

Post by jack0088 »

Sorry, I'm not sure if you're being sarcastic or friendly.. but why does the thread age matter? Why would I create a new thread for the same question anyway? It's a discussion and some questions and solutions still apply today. Maybe I get an answer from somebody else, even if the original author might be not active anymore.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: UDP hole punching

Post by zorg »

jack0088 wrote: Sun Jul 02, 2017 5:39 pm Sorry, I'm not sure if you're being sarcastic or friendly.. but why does the thread age matter? Why would I create a new thread for the same question anyway? It's a discussion and some questions and solutions still apply today. Maybe I get an answer from somebody else, even if the original author might be not active anymore.
A bit of both, to be honest. :3

And it matters because, depending on circumstances like what the thread is about, people usually necropost in threads that have obsolete information in them, for one reason or another (e.g. it was relevant to an old löve version only); but as you stated, since the topic is still relevant now, it's still one of the times that it's actually not an issue, as i originally said.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: UDP hole punching

Post by bartbes »

jack0088 wrote: Fri Jun 30, 2017 7:41 pm So, then I had the idea of having a remote server with open port 42000.
[...]
Turn's out I maybe need to use some NAT hole punching technique to connect the wires...
If your server has an open port, then you don't need hole punching at all! Just make sure to have the client initiate the connection.
jack0088 wrote: Fri Jun 30, 2017 7:41 pm 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.
What do you mean you cannot listen to it? With UDP you don't really "listen" to any specific host, you just get whatever is sent to you. (Though if you've called connect you should only receive packets from the host you connected to.)

Also, getsockname is behaving correctly, since it returns what you're listening on: the ip your computer uses to reach the internet (which is usually the local ip).
User avatar
jack0088
Prole
Posts: 33
Joined: Fri Mar 22, 2013 4:59 am

Re: UDP hole punching

Post by jack0088 »

bartbes wrote: Sun Jul 02, 2017 9:27 pmIf your server has an open port, then you don't need hole punching at all! Just make sure to have the client initiate the connection.
Thats the thing. I opened ports on my remote server so anyone can access it.

I do not have clients or servers in that sense, since the app runs with same code on all devices. Every device can post udp messages and receive others messages. I just open socket and send information to remote server. Then immediatelly change the socket to receive something from that server.

Code: Select all

udp = socket.udp()
udp:settimeout(0)
udp:setsockname(self_ip, port) --force sending through specified port
udp:sendto(msg, remote_server_ip, port) --seems to work

udp:settimeout(.5)
udp:setsockname(remote_server_ip, port) --nothing received
udp:receivefrom()
udp:close()
The app runs on customers device and is in the customers own network. So if the do not forward their port the app is not going to work. And thats what I wanted to overcome. They should not configure anything. It should just work.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests