- gRPC server (
protobuftogofile) - Go
Following build steps are just for initial setup and not needed to execute as the steps have been executed and application can be executed directly using Go.
- Generate
go.modviago mod init grpcChatServer - Create
chat.protofile andchat_serverfolder - Install following dependencies based on OS:
- protobuf
- protoc-gen-go
- protoc-gen-go-grpc
- Generate following in
chat_serverfolder fromchat.protofile viaprotoc --go-grpc_out=require_unimplemented_servers=false:./chat_server/ --go_out=./chat_server/ chat.proto:- chat_grpc.pb.go
- chat.pb.go
- Install
google.golang.org/grpcusinggo getcommand. - Create
chat_server.goas main server function to forward and route client message. - Create
server.goas gRPC server. - Create
client.goas client that connected to gRPC server and send and receive message. - Application at client and server side will terminate once connection is disconnected.
-
Before start, hosting machine should be installed with Go
-
Data Structure - chat.proto
- Git clone this repository to local and open with your preferred IDE.
- Open a terminal and execute
go run server.go. Alternatively, executeenv PORT=9000 go run server.goto change port number to9000. Default port is8080. - Open another terminal and execute
go run client.go - Key in host address [
localhost] with corresponding port stated in Step 2. - Key in username and start sending message.
- Repeat step 3 and 5 for another clients or more.
- All clients should received the message sent by other clients which simulated the chat server.