utp/
lib.rs

1//! Implementation of the [Micro Transport Protocol][spec].
2//!
3//! This library provides both a socket interface (`UtpSocket`) and a stream interface
4//! (`UtpStream`).
5//! I recommend that you use `UtpStream`, as it implements the `Read` and `Write`
6//! traits we all know (and love) from `std::io`, which makes it generally easier to work with than
7//! `UtpSocket`.
8//!
9//! [spec]: http://www.bittorrent.org/beps/bep_0029.html
10//!
11//! # Installation
12//!
13//! Ensure your `Cargo.toml` contains:
14//!
15//! ```toml
16//! [dependencies]
17//! utp = "*"
18//! ```
19//!
20//! # Examples
21//!
22//! ```no_run
23//! extern crate utp;
24//!
25//! use utp::UtpStream;
26//! use std::io::Write;
27//!
28//! fn main() {
29//!     // Connect to an hypothetical local server running on port 8080
30//!     let addr = "127.0.0.1:8080";
31//!     let mut stream = UtpStream::connect(addr).expect("Error connecting to remote peer");
32//!
33//!     // Send a string
34//!     stream.write("Hi there!".as_bytes()).expect("Write failed");
35//!
36//!     // Close the stream
37//!     stream.close().expect("Error closing connection");
38//! }
39//! ```
40//!
41//! Note that you can easily convert a socket to a stream using the `Into` trait, like so:
42//!
43//! ```no_run
44//! # use utp::{UtpStream, UtpSocket};
45//! let socket = UtpSocket::bind("0.0.0.0:0").expect("Error binding socket");
46//! let stream: UtpStream = socket.into();
47//! ```
48
49#![deny(missing_docs)]
50
51extern crate rand;
52extern crate time;
53extern crate num;
54#[macro_use] extern crate log;
55#[cfg(test)] extern crate quickcheck;
56
57// Public API
58pub use socket::UtpSocket;
59pub use socket::UtpListener;
60pub use stream::UtpStream;
61
62mod util;
63mod bit_iterator;
64mod packet;
65mod socket;
66mod stream;