How get Port with net.Addr ?

5,661 views
Skip to first unread message

fast...@gmail.com

unread,
Jul 16, 2011, 6:17:33 PM7/16/11
to golan...@googlegroups.com
Hi
I have connect:
laddr := net.TCPAddr {IP:net.IPv4(127,0,0,1), Port: 0} // Port == 0 - free port
listen, err = net.ListenTCP("tcp4", &laddr)


fmt.Println(addr.Port) //addr.Port undefined (type net.Addr has no field or method Port)

fmt.Println(addr) // Ok. 127.0.0.1:56274 ...
fmt.Println(addr.String()) // Ok. 127.0.0.1:56274 ...
subj

Оne more question. How convert string, []byte to int? 
"string", []byte{"[", "]", "b", "y", "t", "e"}

Thanks

Michael

Paul Borman

unread,
Jul 16, 2011, 6:26:40 PM7/16/11
to golan...@googlegroups.com
addr.(*net.TCPAddr).Port

This is from memory, but I think I did it right.

fast...@gmail.com

unread,
Jul 16, 2011, 6:46:51 PM7/16/11
to golan...@googlegroups.com
It's right. Thanks.
Reply all
Reply to author
Forward
0 new messages