blob: f803e1d76c5e725dad1079a3872a06e642084047 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
use std::net::UdpSocket;
use std::io;
fn make_socket() -> io::Result<()> {
let mut socket = try!(UdpSocket::bind("127.0.0.1:34254"));
// read from the socket
let mut buf = [0; 10];
let (amt, src) = try!(socket.recv_from(&mut buf));
// send a reply to the socket we received data from
let buf = &mut buf[..amt];
buf.reverse();
try!(socket.send_to(buf, &src));
Ok(())
}
fn main() {
make_socket();
}
|