Struct tobytcp::TobyMessenger [] [src]

pub struct TobyMessenger { /* fields omitted */ }

TobyMessenger lets you send messages (in the form of Vec<u8>) over a [TcpStream] [TcpStream]: https://doc.rust-lang.org/std/net/struct.TcpStream.html

Example

// connect to a TobyTcp server
use std::net::TcpStream;
use tobytcp::TobyMessenger;

let stream = TcpStream::connect("127.0.0.1:15235").unwrap();

let mut messenger = TobyMessenger::new(stream);
let (sender, receiver) = messenger.start();

sender.send("Hello!".as_bytes().to_vec()).unwrap();

let recv_buf = receiver.recv().unwrap();

Methods

impl TobyMessenger
[src]

[src]

Create a new TobyMessenger.

[src]

Lets you see the id. Mostly for debugging, as we add the id to logging and thread names.

[src]

Sends the data, encoded as TobyTcp. As opossed to using the sender/receiver, where you will not get feedback on if the write failed.

Apologies if this is awkward. You may want to create a new TobyMessenger, and just call this method on that, but to do so in a multithreaded way would require start() to be threadsafe, which I'm not sure is possible

[src]

Use your TobyMessenger to send data synchronously and know the result!

[src]

Starts all of the threads and queues necessary to do work

The returned Sender is to be used to send messages over the provided TcpStream.

The returned Receiver is to be used to process messages received over the TcpStream.

[src]

Sends a signal to stop all of the threads.

Trait Implementations

Auto Trait Implementations

impl Send for TobyMessenger

impl Sync for TobyMessenger