<commit_before># rust-utp

[![Crate version](http://img.shields.io/badge/crates.io-v0.1.4-blue.svg?style=flat)](https://crates.io/crates/utp)
[![Build Status](http://img.shields.io/travis/meqif/rust-utp.svg?style=flat)](https://travis-ci.org/meqif/rust-utp)

A [Micro Transport Protocol](http://www.bittorrent.org/beps/bep_0029.html)
library implemented in Rust.

The Micro Transport Protocol is a reliable protocol with ordered delivery built
over UDP. Its congestion control algorithm is
[LEDBAT](http://tools.ietf.org/html/rfc6817), which tries to use as much unused
bandwidth as it can but readily yields to competing flows, making it useful for
bulk transfers without introducing congestion in the network.

The current implementation is somewhat incomplete, lacking a complete implementation of congestion
control. However, it does support packet loss detection (except by timeout) the
Selective Acknowledgment extension, handles unordered and duplicate packets and
presents a stream interface (`UtpStream`).

## Building

```sh
git clone https://github.com/meqif/rust-utp.git
cd rust-utp
cargo test
cargo build --release
```

Note that non-release builds are *much* slower.

## Usage

Check the `examples` directory. The simplest example would be:

```rust,no_run
extern crate utp;

use utp::UtpStream;
use std::io::net::ip::{Ipv4Addr, SocketAddr};

fn main() {
    let addr = SocketAddr { ip: Ipv4Addr(127,0,0,1), port: 8080 };

    // Connect to an hypothetical local server running on port 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)<commit_msg>Update example in README.<commit_after># rust-utp

[![Crate version](http://img.shields.io/badge/crates.io-v0.1.4-blue.svg?style=flat)](https://crates.io/crates/utp)
[![Build Status](http://img.shields.io/travis/meqif/rust-utp.svg?style=flat)](https://travis-ci.org/meqif/rust-utp)

A [Micro Transport Protocol](http://www.bittorrent.org/beps/bep_0029.html)
library implemented in Rust.

The Micro Transport Protocol is a reliable protocol with ordered delivery built
over UDP. Its congestion control algorithm is
[LEDBAT](http://tools.ietf.org/html/rfc6817), which tries to use as much unused
bandwidth as it can but readily yields to competing flows, making it useful for
bulk transfers without introducing congestion in the network.

The current implementation is somewhat incomplete, lacking a complete implementation of congestion
control. However, it does support packet loss detection (except by timeout) the
Selective Acknowledgment extension, handles unordered and duplicate packets and
presents a stream interface (`UtpStream`).

## Building

```sh
git clone https://github.com/meqif/rust-utp.git
cd rust-utp
cargo test
cargo build --release
```

Note that non-release builds are *much* slower.

## Usage

Check the `examples` directory. The simplest example would be:

```rust,no_run
extern crate utp;

use utp::UtpStream;
use std::old_io::net::ip::{Ipv4Addr, SocketAddr};

fn main() {
    let addr = SocketAddr { ip: Ipv4Addr(127,0,0,1), port: 8080 };

    // Connect to an hypothetical local server running on port 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)
{'fraction_non_alphanumeric': 0.13376288659793814, 'fraction_numerical': 0.013917525773195877, 'mean_word_length': 3.982028241335045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '274217', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1201, 'n_words': 384}