net.DialTCP - get local port

489 views
Skip to first unread message

Archos

unread,
Jun 17, 2010, 7:30:11 AM6/17/10
to golang-nuts
If net.DialTCP() [1] needs arguments of type *TCPAddr, then how to get
a type TCPAddr for the local address without to know an unused port in
your local host?

// needs a port that you don't know if it's unused
net.ResolveTCPAddr("127.0.0.1")

* Note that net.Dial() [2] can to get the local port automatically:
Dial("tcp", "", "google.com:80")


[1] http://golang.org/pkg/net/#TCPConn.DialTCP
[2] http://golang.org/pkg/net/#Conn.Dial

Roger Pau Monné

unread,
Jun 17, 2010, 7:37:39 AM6/17/10
to Archos, golang-nuts
net.DialTCP("tcp", nil, "google:80")

2010/6/17 Archos <raul...@sent.com>

Archos

unread,
Jun 17, 2010, 7:48:38 AM6/17/10
to golang-nuts
Thanks :)

On Jun 17, 11:37 am, Roger Pau Monné <roy...@gmail.com> wrote:
> net.DialTCP("tcp", nil, "google:80")
>
> 2010/6/17 Archos <raul....@sent.com>
Reply all
Reply to author
Forward
0 new messages