Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Rust/rust-grpc-helloworld/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Rust

Cargo.lock
/target/
14 changes: 14 additions & 0 deletions Rust/rust-grpc-helloworld/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rust-grpc-helloworld"
version = "0.1.0"
authors = ["GitStonic <kingstonicthe1@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
simple_logger = "1.3.0"
protobuf = "2.8.1"
futures = "0.1.29"
grpcio = "0.4"
log = "0.4"
3 changes: 3 additions & 0 deletions Rust/rust-grpc-helloworld/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# rust-grpc-hello-world

An Rust gRPC hello world example...
16 changes: 16 additions & 0 deletions Rust/rust-grpc-helloworld/protos/HelloWorld.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package HelloWorld;

service HelloWorld {
rpc SendHello (Hello) returns (World) {}
}

message World {
string content = 1;
}

message Hello {
string content = 1;
}

23 changes: 23 additions & 0 deletions Rust/rust-grpc-helloworld/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::proto::{HelloWorld as hello_world, HelloWorld_grpc as hello_world_grpc};

use std::io::{self, Read};
use std::sync::Arc;

use grpcio::{ChannelBuilder, EnvBuilder};
use hello_world_grpc::HelloWorldClient;
use hello_world::Hello;

pub fn start() {
let env = Arc::new(EnvBuilder::new().build());
let ch = ChannelBuilder::new(env).connect("127.0.0.1:50051");
let client = HelloWorldClient::new(ch);

info!("Client connected to 127.0.0.1:50051");

let mut req = Hello::default();
req.set_content("World".to_owned());
let reply = client.send_hello(&req)
.expect("Cannot send method");

info!("From server recieved: {}...", reply.get_content());
}
23 changes: 23 additions & 0 deletions Rust/rust-grpc-helloworld/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extern crate simple_logger;
extern crate futures;
extern crate grpcio;
#[macro_use]
extern crate log;

use std::thread;

mod server;
mod client;
mod proto;

fn main() {
simple_logger::init();

info!("Initializing server...");

thread::spawn(move || server::start());

info!("Starting client process...");

client::start();
}
Loading