#[macro_use] extern crate flugrost; use std::net::TcpListener; use std::env; use flugrost::FlugrostProtocol; mod svc { rpc_service!{ rpc greet(s: String) -> String; rpc add(n1: u32, n2: u32) -> u64; rpc sub(n1: u32, n2: u32) -> i64; } pub struct Svc; impl Service for Svc { fn greet(&self, s: String) -> String { s + " from the server!" } fn add(&self, n1: u32, n2: u32) -> u64 { (n1 as u64) + (n2 as u64) } fn sub(&self, n1: u32, n2: u32) -> i64 { (n1 as i64) - (n2 as i64) } } } fn main() { let args: Vec<_> = env::args().collect(); if args.len() != 3 { println!("Usage: {} ip port", args[0]); return; } let host = format!("{}:{}", args[1], args[2]); let socket = TcpListener::bind(host).expect("bind() failed!"); let proto = FlugrostProtocol::new(); let service = svc::Svc; while let Ok((sock, addr)) = socket.accept() { println!("New client from {}", addr); let mut server = svc::SyncServer::from_blocking_socket(&sock, &proto, &service); while let Ok(true) = server.handle_one() {} println!("Client from {} disconnected.", addr); } }