Is there a way to create a UdpSocket without bind () just for send_to ()?

I am trying to make the equivalent of this piece of Ruby :

def color=(color)
  @color = color
  any_bar = UDPSocket.new
  any_bar.connect HOSTNAME, @port
  any_bar.send @color, 0
  any_bar.close
end

I see no other way to initialize UdpSocketfrom the Rust API documentation without bind().

+4
source share
1 answer

I would try ::bind("0.0.0.0:0")- this should let O / S choose the IP / port for you. This may be good enough for a transition socket to send a simple datagram with.

Note. This also happens when using send_to on unconnected UDP sockets, for example. using fd returned from the socket () system call without calling bind () - O / S allocates the IP / port for sending your datagram.

+4

All Articles