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]
pub fn new(tcp_stream: TcpStream) -> TobyMessenger
[src]
Create a new TobyMessenger
.
pub fn id(&self) -> String
[src]
Lets you see the id. Mostly for debugging, as we add the id to logging and thread names.
pub fn sync_send(tcp_stream: TcpStream, data: Vec<u8>) -> Result<()>
[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
pub fn send(&self, data: Vec<u8>) -> Result<()>
[src]
Use your TobyMessenger
to send data synchronously and know the result!
pub fn start(&mut self) -> Result<(Sender<Vec<u8>>, Receiver<Vec<u8>>), ()>
[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
.
pub fn stop_nonblock(&mut self)
[src]
Sends a signal to stop all of the threads.