gortc / stun

Fast RFC 5389 STUN implementation in go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I use it after I get my IP through stun?

xywf221 opened this issue · comments

commented

I think stun is cool, I tried to run the example on Readme, it worked, but how do I use UDP communication?

commented

I try to use the following code, which is not very effective

	conn, err := net.Dial("udp", "140.143.226.61:3478")
	if err != nil {
		panic(err)
	}
	go func() {
		for {
			buf := make([]byte, 1024)
			n, err := conn.Read(buf)
			if err != nil {
				panic(err)
			}
			fmt.Println(buf[0:n])
		}
	}()

	c, err := stun.NewClient(conn)

You can use UDP and this found transport address to send data to your UDP server behind the NAT.

Hi, you should use a de-multiplexer on your UDP "connection".

The low-level example of NAT Traversal can be found at cmd/stun-traversal
I will add more high-level example (with de-multiplexer) soon.

I've created an example, please see cmd/stun-multiplex

commented

I've created an example, please see cmd/stun-multiplex

Ok, I have read it, thank you for your reply.

Note that it will work only for non-symmetric NAT.

Closing for now.