Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

Idiom #121 UDP listen and read

Listen UDP traffic on port p and read 1024 bytes into the buffer b.

use std::net::UdpSocket;
let mut b = [0 as u8; 1024];
let sock = UdpSocket::bind(("localhost", p)).unwrap();
sock.recv_from(&mut b).unwrap();
import std.socket;
ubyte[1024] b;

auto sock = new UdpSocket();
scope(exit) sock.close;

sock.bind(new InternetAddress(p));
sock.receive(b);

New implementation...
< >
programming-idioms.org