Expand description

Usage

Sender example

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

// Send the file with the send_file funciton
send_file(
    Source::Port(port),
    "./examples/file_to_send.txt",
    "127.0.0.1:7890",
)
.await
.expect("error when sending file");

Reciever example

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

recv_file(
    Source::Port(port),
    &mut File::create("output_from_recv.txt").expect("could not create output file"),
    "127.0.0.1:3456",
    ProgressTracking::Memory,
)
.await
.expect("error when sending file");

Sending files

Messages

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.

Sending

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.

Re-exports

pub use reciever::recv_file;
pub use sender::send_file;

Modules

Structs

A reference to an open file on the filesystem.

Enums

This is the source of sending or recieving a file It always uses an Arced udp socket or Arc<UdpSocket>.