Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: UDPConn.LocalAddr() of ListenUDP returns "0.0.0.0:11110" instead of "127.0.0.1:58306" or "10.16.83.185:51386" #26346

Closed
woniuxu opened this issue Jul 12, 2018 · 0 comments

Comments

@woniuxu
Copy link

woniuxu commented Jul 12, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 linux/amd64

What did you do?

Server side:

ServerAddr,err := net.ResolveUDPAddr("udp",":11110")
ServerConn, err := net.ListenUDP("udp", ServerAddr)
n,addr,err := ServerConn.ReadFromUDP(buf)
fmt.Println("Received ",string(buf[0:n]), " from ",addr, " to ", ServerConn.LocalAddr())

Client side:

ServerAddr1,err := net.ResolveUDPAddr("udp", "10.16.83.185:11110")
Conn1, err := net.DialUDP("udp", nil, ServerAddr1)
_,err := Conn1.Write(buf)

ServerAddr2,err := net.ResolveUDPAddr("udp", "127.0.0.1:11110")
Conn2, err := net.DialUDP("udp", nil, ServerAddr2)
_,err := Conn1.Write(buf)

What did you expect to see?

Received  1  from  10.16.83.185:51386  to  10.16.83.185:11110
Received  1  from  127.0.0.1:58306  to  127.0.0.1:11110

What did you see instead?

Received  1  from  10.16.83.185:51386  to  0.0.0.0:11110
Received  1  from  127.0.0.1:58306  to  0.0.0.0:11110

So what shoud i do to get the "expect" result? Thanks.

@woniuxu woniuxu closed this as completed Jul 12, 2018
@mikioh mikioh changed the title net:UDPConn.LocalAddr() of ListenUDP returns "0.0.0.0:11110" instead of "127.0.0.1:58306" or "10.16.83.185:51386" net: UDPConn.LocalAddr() of ListenUDP returns "0.0.0.0:11110" instead of "127.0.0.1:58306" or "10.16.83.185:51386" Feb 26, 2019
@golang golang locked and limited conversation to collaborators Feb 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants