Lines Matching full:socket
11 /// A UDP socket.
13 /// After creating a `UdpSocket` by [`bind`]ing it to a socket address, data can be
14 /// [sent to] and [received from] any other socket address.
42 /// let socket = UdpSocket::bind("127.0.0.1:34254")?;
44 /// // Receives a single datagram message on the socket. If `buf` is too small to hold
47 /// let (amt, src) = socket.recv_from(&mut buf)?;
52 /// socket.send_to(buf, &src)?;
53 /// } // the socket is closed here
61 /// Creates a UDP socket from the given address.
67 /// each of the addresses until one succeeds and returns the socket. If none
68 /// of the addresses succeed in creating a socket, the error returned from
73 /// Creates a UDP socket bound to `127.0.0.1:3400`:
78 /// let socket = UdpSocket::bind("127.0.0.1:3400").expect("couldn't bind to address");
81 /// Creates a UDP socket bound to `127.0.0.1:3400`. If the socket cannot be
82 /// bound to that address, create a UDP socket bound to `127.0.0.1:3401`:
91 /// let socket = UdpSocket::bind(&addrs[..]).expect("couldn't bind to address");
94 /// Creates a UDP socket bound to a port assigned by the operating system
100 /// let socket = UdpSocket::bind("127.0.0.1:0").unwrap();
107 /// Receives a single datagram message on the socket. On success, returns the number
119 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
121 /// let (number_of_bytes, src_addr) = socket.recv_from(&mut buf)
130 /// Receives a single datagram message on the socket, without removing it from the
148 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
150 /// let (number_of_bytes, src_addr) = socket.peek_from(&mut buf)
159 /// Sends data on the socket to the given address. On success, returns the
168 /// This will return an error when the IP version of the local socket
178 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
179 /// socket.send_to(&[0; 10], "127.0.0.1:4242").expect("couldn't send data");
193 /// Returns the socket address of the remote peer this socket was connected to.
200 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
201 /// socket.connect("192.168.0.1:41203").expect("couldn't connect to address");
202 /// assert_eq!(socket.peer_addr().unwrap(),
206 /// If the socket isn't connected, it will return a [`NotConnected`] error.
213 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
214 /// assert_eq!(socket.peer_addr().unwrap_err().kind(),
222 /// Returns the socket address that this socket was created from.
229 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
230 /// assert_eq!(socket.local_addr().unwrap(),
238 /// Creates a new independently owned handle to the underlying socket.
240 /// The returned `UdpSocket` is a reference to the same socket that this
242 /// options set on one socket will be propagated to the other.
249 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
250 /// let socket_clone = socket.try_clone().expect("couldn't clone the socket");
278 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
279 /// socket.set_read_timeout(None).expect("set_read_timeout call failed");
290 /// let socket = UdpSocket::bind("127.0.0.1:34254").unwrap();
291 /// let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
321 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
322 /// socket.set_write_timeout(None).expect("set_write_timeout call failed");
333 /// let socket = UdpSocket::bind("127.0.0.1:34254").unwrap();
334 /// let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
343 /// Returns the read timeout of this socket.
354 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
355 /// socket.set_read_timeout(None).expect("set_read_timeout call failed");
356 /// assert_eq!(socket.read_timeout().unwrap(), None);
363 /// Returns the write timeout of this socket.
374 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
375 /// socket.set_write_timeout(None).expect("set_write_timeout call failed");
376 /// assert_eq!(socket.write_timeout().unwrap(), None);
383 /// Sets the value of the `SO_BROADCAST` option for this socket.
385 /// When enabled, this socket is allowed to send packets to a broadcast
393 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
394 /// socket.set_broadcast(false).expect("set_broadcast call failed");
401 /// Gets the value of the `SO_BROADCAST` option for this socket.
410 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
411 /// socket.set_broadcast(false).expect("set_broadcast call failed");
412 /// assert_eq!(socket.broadcast().unwrap(), false);
419 /// Sets the value of the `IP_MULTICAST_LOOP` option for this socket.
421 /// If enabled, multicast packets will be looped back to the local socket.
429 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
430 /// socket.set_multicast_loop_v4(false).expect("set_multicast_loop_v4 call failed");
437 /// Gets the value of the `IP_MULTICAST_LOOP` option for this socket.
446 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
447 /// socket.set_multicast_loop_v4(false).expect("set_multicast_loop_v4 call failed");
448 /// assert_eq!(socket.multicast_loop_v4().unwrap(), false);
455 /// Sets the value of the `IP_MULTICAST_TTL` option for this socket.
458 /// this socket. The default value is 1 which means that multicast packets
468 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
469 /// socket.set_multicast_ttl_v4(42).expect("set_multicast_ttl_v4 call failed");
476 /// Gets the value of the `IP_MULTICAST_TTL` option for this socket.
485 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
486 /// socket.set_multicast_ttl_v4(42).expect("set_multicast_ttl_v4 call failed");
487 /// assert_eq!(socket.multicast_ttl_v4().unwrap(), 42);
494 /// Sets the value of the `IPV6_MULTICAST_LOOP` option for this socket.
496 /// Controls whether this socket sees the multicast packets it sends itself.
504 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
505 /// socket.set_multicast_loop_v6(false).expect("set_multicast_loop_v6 call failed");
512 /// Gets the value of the `IPV6_MULTICAST_LOOP` option for this socket.
521 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
522 /// socket.set_multicast_loop_v6(false).expect("set_multicast_loop_v6 call failed");
523 /// assert_eq!(socket.multicast_loop_v6().unwrap(), false);
530 /// Sets the value for the `IP_TTL` option on this socket.
533 /// from this socket.
540 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
541 /// socket.set_ttl(42).expect("set_ttl call failed");
548 /// Gets the value of the `IP_TTL` option for this socket.
557 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
558 /// socket.set_ttl(42).expect("set_ttl call failed");
559 /// assert_eq!(socket.ttl().unwrap(), 42);
568 /// This function specifies a new multicast group for this socket to join.
580 /// This function specifies a new multicast group for this socket to join.
604 /// Gets the value of the `SO_ERROR` option on this socket.
606 /// This will retrieve the stored error in the underlying socket, clearing
615 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
616 /// match socket.take_error() {
627 /// Connects this UDP socket to a remote address, allowing the `send` and
641 /// Creates a UDP socket bound to `127.0.0.1:3400` and connect the socket to
647 /// let socket = UdpSocket::bind("127.0.0.1:3400").expect("couldn't bind to address");
648 /// socket.connect("127.0.0.1:8080").expect("connect function failed");
652 /// function of a UDP socket is not a useful thing to do: The OS will be
660 /// Sends data on the socket to the remote address to which it is connected.
662 /// [`UdpSocket::connect`] will connect this socket to a remote address. This
663 /// method will fail if the socket is not connected.
670 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
671 /// socket.connect("127.0.0.1:8080").expect("connect function failed");
672 /// socket.send(&[0, 1, 2]).expect("couldn't send message");
679 /// Receives a single datagram message on the socket from the remote address to
686 /// [`UdpSocket::connect`] will connect this socket to a remote address. This
687 /// method will fail if the socket is not connected.
694 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
695 /// socket.connect("127.0.0.1:8080").expect("connect function failed");
697 /// match socket.recv(&mut buf) {
707 /// Receives single datagram on the socket from the remote address to which it is
721 /// [`UdpSocket::connect`] will connect this socket to a remote address. This
722 /// method will fail if the socket is not connected.
726 /// This method will fail if the socket is not connected. The `connect` method
727 /// will connect this socket to a remote address.
734 /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
735 /// socket.connect("127.0.0.1:8080").expect("connect function failed");
737 /// match socket.peek(&mut buf) {
747 /// Moves this UDP socket into or out of nonblocking mode.
762 /// Creates a UDP socket bound to `127.0.0.1:7878` and read bytes in
769 /// let socket = UdpSocket::bind("127.0.0.1:7878").unwrap();
770 /// socket.set_nonblocking(true).unwrap();
775 /// match socket.recv_from(&mut buf) {
778 /// // wait until network socket is ready, typically implemented