Comments (4)
Could you please point me to the example on how to setup a TCP connection between 2 nodes both behind NAT?
Something like node1_code.go, node2_code.go, external_server_code.go
Thanks!
from go-stun.
@isaachess Yes, It should work exactly you described, but currently stun.Discover uses net.Dial instead of Listen (so, the socket is associated with a STUN-server's address) and hole-punching does not work. I'll fix it, thanks.
from go-stun.
I just spent the better part of a day tearing my hair out over this, so I wanted to make sure that I documented exactly what's happening here, in the hopes that someone else won't have to.
Although @pixelbender fixed the issue with the fact that net.Listen*
wasn't being used, the net.PacketConn
returned by Discover()
isn't actually relinquished in a way that allows it to be repurposed! When the Conn
is created, an Agent
is set up to handle it. Upon start, the Agent
calls this method, which calls ReadFrom
on the net.PacketConn
to loop over/handle received messages. Turns out, when the net.PacketConn
is handed back to you from Discover()
, that loop is never actually stopped.
I guess that's what @pixelbender meant by the TODO: hijack
comment 😜 Anyway, long story short, it turns out that this issue hasn't really been addressed.
from go-stun.
@isaachess That PR (#8) should allow you to use this library for hole-punching. The net.PacketConn
you get back is now usable, so if you know the public address (host/port) of your peer, you can get them to try to send packets to one another at the same time.
For what it's worth, you'll do something like this for both clients (although you still need an external service to help them exchange addresses):
conn, externalAddr, err := stun.Discover(STUNServer)
if err != nil {
return nil, errors.Wrap(err, "failed to set up public UDP socket")
}
peerExternalAddr := &net.UDPAddr{
IP: net.ParseIP("<peer addr>"),
Port: 1234,
}
conn.WriteTo([]byte("hello"), peerExternalAddr)
from go-stun.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-stun.