This file contains 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
port := 50051 // we'll implement command line arguments leter | |
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *port)) | |
if err != nil { | |
log.Fatalf("failed to listen: %v", err) | |
} |
This file contains 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
func (s *theSocialRobotServer) EventStream(stream pb.TheSocialRobot_EventStreamServer) error { | |
for { | |
// TODO handle events from the client | |
_, err := stream.Recv() | |
if err == io.EOF { | |
return nil | |
} | |
if err != nil { | |
return err | |
} |
This file contains 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
stream.Send(command) |
This file contains 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
command := &pb.BodyCommand{ | |
Id: 1, | |
Actions: {% raw %} []*pb.Action{{Delay: 0, Action: &pb.Action_Say{Say: &pb.Say{Text: "Hello World"}}}}, {% endraw %} | |
} |
This file contains 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
_, err := stream.Recv() | |
if err == io.EOF { | |
return nil | |
} | |
if err != nil { | |
return err | |
} |
This file contains 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
type theSocialRobotServer struct { | |
pb.UnimplementedTheSocialRobotServer | |
} | |
func (s *theSocialRobotServer) EventStream(stream pb.TheSocialRobot_EventStreamServer) error { | |
// TBD | |
} |
This file contains 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
// TheSocialRobotServer is the server API for TheSocialRobot service. | |
// All implementations must embed UnimplementedTheSocialRobotServer | |
// for forward compatibility | |
type TheSocialRobotServer interface { | |
EventStream(TheSocialRobot_EventStreamServer) error | |
mustEmbedUnimplementedTheSocialRobotServer() | |
} |
This file contains 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
import pb "github.com/TheSocialRobot/BrainCore/thesocialrobot" |
This file contains 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
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative thesocialrobot/thesocialrobot.proto |
This file contains 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
# get the protobuf compiler, protoc, for Linux | |
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.5/protoc-21.5-linux-x86_64.zip | |
# unpack the zip file and move the protoc command to a convenient directory in your path | |
mkdir tmp-protoc ; cd tmp-protoc | |
unzip protoc-21.5-linux-x86_64.zip | |
mv bin/proto ~/.local/bin | |
cd .. ; rm -rf tmp-protoc | |
# install gRPC plugins for go |