#udp #filesharing


used for sending files in rust

7 releases

0.1.6 Mar 21, 2022
0.1.5 Mar 20, 2022

#1230 in Command line utilities

Used in mork


654 lines


Rust crate for sending files p2p over udp

Getting started

You can look in the /examples folder for examples

You can also look in the official documentation


This is used in my other project


This software is dual-licenced under MIT and Apache-2.0.




Sender example

let port = 3456;
println!("my ip:{}", port);

// Send the file with the send_file funciton
.expect("error when sending file");


Reciever example

let port = 7890;
println!("my ip:{}", port);

    &mut File::create("output_from_recv.txt").expect("could not create output file"),
.expect("error when sending file");

Sending files


Messages are 508 bytes in size. This is because that is the biggest message you can send over udp without getting dropped.

The first 8 bytes or 64 bits in the message are used for telling what message this is. The counting starts at 0.

The rest is content of the file

Hole punch

A hole punch is a way for clients to communicate without requireing a port-forward.

Here is a wikipedia article about it.

But it works like this

  1. Client A sends a udp message to client B:s ip-address and port.
  2. Client B does the same as client A but with client A:s ip-address and port.
  3. Now they are able to send messages over udp from where they have hole-punched to.

Progress tracking

When recieving the reciever remembers what messages have been sent. It also knows how many that should be sent. With that info it can tell the sender what messages are unsent.

The progress tracking can be stored in memory and on file if the messages are to many.

You can calculate the memory required for recieving a file, file size / 500 / 8 = size of progress tracker.

Example: 64gb = 64 000 000 000 / 500 / 8 = 16 000 000 = 16mb

The progress tracker for 64gb is 16mb.


It sends the file by sending many messages. When it's done it will send a message telling the reciever that it's done. If any messages got dropped the reciever will send a list of those. If the file was recieved correctly the reciever will send a message.


~124K SLoC