Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.
This repository was archived by the owner on Apr 16, 2020. It is now read-only.

How to write codes in the server when the proto file has more than one services ?  #200

Open
@najcit

Description

@najcit

the content of the proto file:

syntax = "proto3";
package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
service Talk {
rpc TalkSomething (TalkRequest) returns (TalkReply) {}
}

message TalkRequest {
string name = 1;
}

message TalkReply {
string message = 1;
}

the codes of the server.rs file:
let new_service = server::GreeterServer::new(Greet);

let mut server = Server::new(new_service);

let http = Http::new().http2_only(true).clone();

let addr = "[::1]:50051".parse().unwrap();
let bind = TcpListener::bind(&addr).expect("bind");

let serve = bind
    .incoming()
    .for_each(move |sock| {
        if let Err(e) = sock.set_nodelay(true) {
            return Err(e);
        }

        let serve = server.serve_with(sock, http.clone());
        tokio::spawn(serve.map_err(|e| error!("hyper error: {:?}", e)));

        Ok(())
    })
    .map_err(|e| eprintln!("accept error: {}", e));

tokio::run(serve)

how to modify these code ?
thank you!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions