Skip to content
This repository has been archived by the owner on Jun 5, 2021. It is now read-only.

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

Closed
xywf221 opened this issue May 9, 2019 · 6 comments
Closed

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

xywf221 opened this issue May 9, 2019 · 6 comments

Comments

@xywf221
Copy link

xywf221 commented May 9, 2019

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

@xywf221
Copy link
Author

xywf221 commented May 9, 2019

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)

@songjiayang
Copy link
Contributor

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

@ernado
Copy link
Collaborator

ernado commented May 9, 2019

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.

@ernado
Copy link
Collaborator

ernado commented May 9, 2019

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

@xywf221
Copy link
Author

xywf221 commented May 10, 2019

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

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

@ernado
Copy link
Collaborator

ernado commented May 11, 2019

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

Closing for now.

@ernado ernado closed this as completed May 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants