Sending UDP packets, getting error "use of WriteTo with pre-connected UDP"

2,509 views
Skip to first unread message

Torrance Hodgson

unread,
Sep 18, 2013, 12:35:21 AM9/18/13
to golan...@googlegroups.com
Hi all,

I would like to send UDP packets using (c *net.UDPConn).WriteToUDP([]byte), however I'm getting an error "use of WriteTo with pre-connected UDP".

Looking at the net package code, I can see it is checking whether (c *net.UDPConn).fd.isConnected and returning the error if true. I presume my UDP connection is 'connected' since I initialized the variable using UDPDial(), but I can't see how else to properly initialise the UDPConn to avoid this.

How can use WriteToUDP() without generating this error?

Torrance

Dave Cheney

unread,
Sep 18, 2013, 12:44:39 AM9/18/13
to Torrance Hodgson, golang-nuts
http://play.golang.org/p/ygGFr9oLpW may work, i'm very rust around he
semantics of connected and unconnected UDP sockets.
> --
> 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/groups/opt_out.

Torrance Hodgson

unread,
Sep 18, 2013, 12:59:32 AM9/18/13
to golan...@googlegroups.com, Torrance Hodgson
You're exactly right. Thank you again!
Reply all
Reply to author
Forward
0 new messages