I'm trying to do 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 can't see any other way to initialize a UdpSocket
from the Rust API documentation without bind()
.
As far as I remember bind is not required for a UDP socket because a bind call is made for you by the stack.
UDP socket routines enable simple IP communication using the user datagram protocol (UDP). The User Datagram Protocol (UDP) runs on top of the Internet Protocol (IP) and was developed for applications that do not require reliability, acknowledgment, or flow control features at the transport layer.
I would try ::bind("0.0.0.0:0")
- this should let the O/S choose an IP/port for you. This might be good enough for a transient socket to send a simple datagram with.
Note: this is what happens too when using sendto() on an unbound UDP socket too, e.g. using the fd returned from the socket() system call without calling bind() - the O/S allocates an IP/port to send your datagram from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With