codemp/src/server.rs

41 lines
872 B
Rust
Raw Normal View History

2022-07-10 19:01:56 +02:00
use tonic::{transport::Server, Request, Response, Status};
use proto_core::session_server::{Session, SessionServer};
use proto_core::{SessionRequest, SessionResponse};
2022-07-10 19:01:56 +02:00
pub mod proto_core {
tonic::include_proto!("core");
}
#[derive(Debug, Default)]
pub struct TestSession {}
#[tonic::async_trait]
impl Session for TestSession {
async fn create(
&self,
request: Request<SessionRequest>,
) -> Result<Response<SessionResponse>, Status> {
println!("Got a request: {:?}", request);
let reply = proto_core::SessionResponse {
session_id: request.into_inner().session_id,
};
Ok(Response::new(reply))
}
}
2022-07-10 19:01:56 +02:00
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse()?;
let greeter = TestSession::default();
2022-07-10 19:01:56 +02:00
Server::builder()
.add_service(SessionServer::new(greeter))
.serve(addr)
.await?;
2022-07-10 19:01:56 +02:00
Ok(())
2022-07-10 19:01:56 +02:00
}