- gRPC server (
protobuf
togo
file) - 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.mod
viago mod init grpcChatServer
- Create
chat.proto
file andchat_server
folder - Install following dependencies based on OS:
- protobuf
- protoc-gen-go
- protoc-gen-go-grpc
- Generate following in
chat_server
folder fromchat.proto
file 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/grpc
usinggo get
command. - Create
chat_server.go
as main server function to forward and route client message. - Create
server.go
as gRPC server. - Create
client.go
as 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.go
to 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.