Last active
May 9, 2017 23:07
-
-
Save scionwest/ca07adba0e2fcea681bbe21c711568a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gRPC channel | |
var channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure); | |
// Protobuf service | |
var client = new Messenger.MessengerClient(channel); | |
// Protobuf model | |
var request = new HelloRequest { Name = "You" }; | |
var reply = await client.SayHelloAsync(request); | |
channel.ShutdownAsync().Wait(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
package AComms.Services; | |
// Client service definitions | |
service Messenger { | |
// Send a greeting message | |
rpc SayHello(HelloRequest) returns (HelloReply) {} | |
} | |
// The request message | |
message HelloRequest { | |
string Name = 1; | |
} | |
message HelloReply { | |
string message = 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AComms | |
{ | |
internal class MessengerService : Messenger.MessengerBase | |
{ | |
// Listen for SayHello requests from client and react. | |
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context) | |
{ | |
return Task.FromResult(new HelloReply { Message = "Hello " + request.Name }); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var server = new Server | |
{ | |
// Protobuf service | |
Services = { Messenger.BindService(new MessengerService()) }, | |
Ports = { new ServerPort("localhost", 50051, ServerCredentials.Insecure) } | |
}; | |
server.Start(); | |
Console.WriteLine("Server running\nPress any key to stop."); | |
Console.ReadKey(); | |
server.ShutdownAsync().Wait(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment