[Gambas-user] UDP hole punching
Mayost Sharon
sharon at 455.co.il
Thu Jun 3 01:04:57 CEST 2021
Hello everyone
I am attaching a demo that shows it works beautifully.
My mistake, I thought it was not necessary for both clients to be connected to the server
One more thing to pay attention to!
Need to occasionally communicate minimally with the server, otherwise it may lose connection
I did an experiment and it works very nicely
There should be two connection clients each client sitting at a separate address behind Nat
This client is: udp_02
Need another third place that is with an open public address is the server
This server: udp_01
Run the server: (For example the server address is: 1.2.3.4)
udp_01.gambas 0.0.0.0 8060
Customer A:
udp_02.gambas 1.2.3.4 8060
Customer B:
udp_02.gambas 1.2.3.4 8060
To see that it's safe working try to stop the server and see that there is still a direct connection between A and B.
P2P
Thank you
---------- Original Message -----------
From: Brian G <brian at westwoodsvcs.com>
To: Gambas mailing list <user at lists.gambas-basic.org>
Sent: Tue, 1 Jun 2021 16:01:23 -0700 (PDT)
Subject: Re: [Gambas-user] UDP hole punching
> I thought the nat took care of that..
>
> Flow:
>
> A and B each begin a UDP conversation with S; the NAT devices NA and NB create
> UDP translation states and assign temporary external port numbers EPA and EPB.
>
> S examines the UDP packets to get the source port used by NA and NB (the
> external NAT ports EPA and EPB).
>
> S passes EIPA:EPA to B and EIPB:EPB to A.
>
> A sends a packet to EIPB:EPB.
>
> NA examines A's packet and creates the following tuple in its translation
> table: (Source-IP-A, EPA, EIPB, EPB).
>
> B sends a packet to EIPA:EPA.
>
> NB examines B's packet and creates the following tuple in its translation
> table: (Source-IP-B, EPB, EIPA, EPA).
>
> Depending on the state of NA's translation table when B's first packet arrives
>
> (i.e. whether the tuple (Source-IP-A, EPA, EIPB, EPB) has been created by
> the time of arrival of B's first packet), B's first packet is dropped (no
> entry in translation table) or passed (entry in translation table has been
> made).
>
> Depending on the state of NB's translation table when A's first packet arrives
>
> (i.e. whether the tuple (Source-IP-B, EPB, EIPA, EPA) has been created by
> the time of arrival of A's first packet), A's first packet is dropped (no
> entry in translation table) or passed (entry in translation table has been
> made).
>
> At worst, the second packet from A reaches B; at worst the second packet from
> B reaches A. Holes have been "punched" in the NAT and both hosts can
> directly communicate.
>
> >From this it looks like your app get a message from S the go between containing the ip and port and then creates an outbound connection to the other host
> looks like you just need to read s's message and create a new udp connection
> to B.
>
> Maybe I am just miss reading or don't get what you are doing.
>
> Do you have a sample program?
>
> "Failure is the key to success;
> each mistake teaches us something" .. Morihei Ueshiba
> Brian G
>
> ----- On Jun 1, 2021, at 10:43 AM, Mayost Sharon sharon at 455.co.il wrote:
>
> > Hello to you
> >
> > Can it be done:
> > UDP hole punching
> > Through:
> > gb.net
> >
> > I understand that I need to change:
> > UdpSocket.SourceHost and UdpSocket.SourcePort
> > And they are for reading only
> > They cannot be changed
> >
> > Is there another way to perform: UDP hole punching
> >
> > Thank you
> >
> > ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
------- End of Original Message -------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: udp_01.zip
Type: application/zip
Size: 15466 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210603/21d11624/attachment-0002.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: udp_02.zip
Type: application/zip
Size: 15710 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210603/21d11624/attachment-0003.zip>
More information about the User
mailing list