Trait PacketTransfer

Source
pub trait PacketTransfer {
    // Required methods
    fn connect(&mut self) -> Result<(), String>;
    fn peek(&mut self, tag: &str) -> Result<Option<Vec<u8>>, String>;
    fn send(&mut self, tag: &str, data: Vec<u8>) -> Result<(), String>;
    fn remove(&mut self, tag: &str) -> Result<(), String>;

    // Provided method
    fn recv(&mut self, tag: &str) -> Result<Option<Vec<u8>>, String> { ... }
}
Expand description

A packet transfer protocol. It is similear to StreamTransfer trait but provides a tag for transfer index.

Required Methods§

Source

fn connect(&mut self) -> Result<(), String>

Connect to host. Most implments should make sure the server / other peer is avaliable.

Source

fn peek(&mut self, tag: &str) -> Result<Option<Vec<u8>>, String>

Try to receive a data packet.

Source

fn send(&mut self, tag: &str, data: Vec<u8>) -> Result<(), String>

Try to send a data packet to the server / other peer.

Source

fn remove(&mut self, tag: &str) -> Result<(), String>

Remove the packet from the queue.

Provided Methods§

Source

fn recv(&mut self, tag: &str) -> Result<Option<Vec<u8>>, String>

Try to receive a data packet and remove it.

Implementors§