Timeouts on TCP Dial

860 views
Skip to first unread message

Matt Joiner

unread,
Jul 17, 2014, 1:49:22 AM7/17/14
to golan...@googlegroups.com
I'm looking to do TCP dials with timeouts and specify local address. I see there was some work done on this with DialOpt, and suggestions of DialTCPTimeout. What's the status of this? What's the best way to work around it in the meanwhile?

Benjamin Measures

unread,
Jul 18, 2014, 8:39:32 AM7/18/14
to golan...@googlegroups.com
On Thursday, 17 July 2014 06:49:22 UTC+1, Matt Joiner wrote:
I'm looking to do TCP dials with timeouts and specify local address.

d := &net.Dialer{Timeout: 3 * time.Second}
c, err := d.Dial("tcp", "localhost:81")

Gustavo Niemeyer

unread,
Jul 18, 2014, 11:55:26 AM7/18/14
to Matt Joiner, golan...@googlegroups.com
It already exists:

http://golang.org/pkg/net#DialTimeout
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

gustavo @ http://niemeyer.net

Matt Harden

unread,
Jul 20, 2014, 12:38:36 AM7/20/14
to Gustavo Niemeyer, Matt Joiner, golang-nuts
I believe that the OP wanted to specify the source IP of the TCP connection as well. In that case, Dialer can do it (as well as the timeout) but DialTimeout cannot. See the LocalAddr and Timeout fields of the net.Dialer struct.

Matt Joiner

unread,
Jul 21, 2014, 2:27:09 AM7/21/14
to Matt Harden, Gustavo Niemeyer, golang-nuts
Thanks all. Somehow I didn't notice Dialer in the net package, and it has what I need.
Reply all
Reply to author
Forward
0 new messages