Update README

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 4 years ago
parent 49dd76c142
commit f25e96c2ae
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,2 +1,25 @@
# msg-rpc
An rpc server implementation using msgpack
## Usage
Add the crate to the dependencies
```toml
[dependencies]
msgrpc = {git = "https://github.com/flotte-goes-smart/msg-rpc/tree/main"}
```
```rust
pub fn main() {
let mut server = RPCServer::new("127.0.0.1:".to_string());
let mut receiver = Arc::clone(&server.receiver);
thread::spawn(move || {
server.start();
});
for handler in receiver {
// handle the message and return a response
}
}
```

@ -4,7 +4,7 @@ use std::io;
use byteorder::{BigEndian, ByteOrder};
use crate::message::Message;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{Receiver, Sender};
use std::sync::mpsc::{Receiver, Sender, channel};
use crossbeam_utils::sync::WaitGroup;
use std::mem;
@ -32,6 +32,17 @@ pub struct RpcServer {
}
impl RpcServer {
/// Creates a new RPC Server
pub fn new(address: String) -> Self {
let (tx, rx) = channel();
Self {
address,
sender: tx,
receiver: Arc::new(Mutex::new(rx))
}
}
/// Starts the RPC server
pub fn start(&mut self) -> io::Result<()> {
let listener = TcpListener::bind(&self.address)?;

Loading…
Cancel
Save