Crate utp [−] [src]
Implementation of the Micro Transport Protocol.
This library provides both a socket interface (UtpSocket
) and a stream interface
(UtpStream
).
I recommend that you use UtpStream
, as it implements the Read
and Write
traits we all know (and love) from std::io
, which makes it generally easier to work with than
UtpSocket
.
Installation
Ensure your Cargo.toml
contains:
[dependencies]
utp = "*"
Examples
extern crate utp; use utp::UtpStream; use std::io::{Read, Write}; fn main() { // Connect to an hypothetical local server running on port 8080 let addr = "127.0.0.1:8080"; let mut stream = match UtpStream::connect(addr) { Ok(stream) => stream, Err(e) => panic!("{}", e), }; // Send a string match stream.write("Hi there!".as_bytes()) { Ok(_) => (), Err(e) => println!("Write failed with {}", e) } // Close the stream match stream.close() { Ok(()) => println!("Connection closed"), Err(e) => println!("{}", e) } }
Note that you can easily convert a socket to a stream using the Into
trait, like so:
let socket = UtpSocket::bind("0.0.0.0:0").unwrap(); let stream: UtpStream = socket.into();
Structs
UtpListener |
A structure representing a socket server. |
UtpSocket |
A structure that represents a uTP (Micro Transport Protocol) connection between a local socket and a remote socket. |
UtpStream |
A structure that represents a uTP (Micro Transport Protocol) stream between a local socket and a remote socket. |