Compare commits

..

No commits in common. "bfcaba33ab4f836b4b22cfefa8ef6aa99a43b3c9" and "1f354bf71e45f627cb8db396ffc611945c59b37d" have entirely different histories.

5 changed files with 19 additions and 18 deletions

2
go.mod
View File

@ -1,4 +1,4 @@
module grpc-ping module lume-grpc
go 1.16 go 1.16

View File

@ -25,7 +25,7 @@ type PingRequest struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Seq uint64 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,omitempty"` Seq uint32 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,omitempty"`
Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
} }
@ -61,7 +61,7 @@ func (*PingRequest) Descriptor() ([]byte, []int) {
return file_ping_ping_proto_rawDescGZIP(), []int{0} return file_ping_ping_proto_rawDescGZIP(), []int{0}
} }
func (x *PingRequest) GetSeq() uint64 { func (x *PingRequest) GetSeq() uint32 {
if x != nil { if x != nil {
return x.Seq return x.Seq
} }
@ -80,7 +80,7 @@ type PingResponse struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Seq uint64 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,omitempty"` Seq uint32 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,omitempty"`
Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
} }
@ -116,7 +116,7 @@ func (*PingResponse) Descriptor() ([]byte, []int) {
return file_ping_ping_proto_rawDescGZIP(), []int{1} return file_ping_ping_proto_rawDescGZIP(), []int{1}
} }
func (x *PingResponse) GetSeq() uint64 { func (x *PingResponse) GetSeq() uint32 {
if x != nil { if x != nil {
return x.Seq return x.Seq
} }
@ -136,16 +136,16 @@ var file_ping_ping_proto_rawDesc = []byte{
0x0a, 0x0f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x0a, 0x0f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x33, 0x0a, 0x0b, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x6f, 0x12, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x33, 0x0a, 0x0b, 0x50, 0x69, 0x6e, 0x67, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x71, 0x18, 0x01, 0x20, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x71, 0x18, 0x01, 0x20,
0x01, 0x28, 0x04, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x34, 0x0a, 0x0c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x34, 0x0a, 0x0c,
0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03,
0x73, 0x65, 0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x12, 0x73, 0x65, 0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x12,
0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61,
0x74, 0x61, 0x32, 0x37, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69, 0x74, 0x61, 0x32, 0x37, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69,
0x6e, 0x67, 0x12, 0x11, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x6e, 0x67, 0x12, 0x11, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x69, 0x6e, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x69, 0x6e,
0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x10, 0x5a, 0x0e, 0x67, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x10, 0x5a, 0x0e, 0x6c,
0x72, 0x70, 0x63, 0x2d, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x75, 0x6d, 0x65, 0x2d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }

View File

@ -1,6 +1,6 @@
syntax = "proto3"; syntax = "proto3";
option go_package = "grpc-ping/ping"; option go_package = "lume-grpc/ping";
package ping; package ping;
@ -9,11 +9,11 @@ service ping {
} }
message PingRequest { message PingRequest {
uint64 seq = 1; uint32 seq = 1;
string data = 2; string data = 2;
} }
message PingResponse { message PingResponse {
uint64 seq = 1; uint32 seq = 1;
string data = 2; string data = 2;
} }

View File

@ -9,7 +9,7 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
pb "grpc-ping/ping" pb "lume-grpc/ping"
) )
const ( const (
@ -26,7 +26,7 @@ func genPayload(s int) string {
} }
func main() { func main() {
var i uint64 var i uint32
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel() defer cancel()
@ -43,14 +43,16 @@ func main() {
for i = 1; ; i++ { for i = 1; ; i++ {
rtt := time.Now() rtt := time.Now()
ctx, cancel = context.WithTimeout(context.Background(), time.Second) ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
r, err := c.Ping(ctx, &pb.PingRequest{Data: data, Seq: i}) r, err := c.Ping(ctx, &pb.PingRequest{Data: data, Seq: i})
if err != nil { if err != nil {
log.Printf("could not connect to: %v", err) log.Printf("could not connect to: %v", err)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
continue continue
} }
// log.Printf("%d characters roundtrip to (%s): seq=%d time=%s", len(r.Data), address, r.Seq, time.Since(rtt))
fmt.Printf("%d bytes from %s: seq=%d time=%s\n", len(r.Data), address, r.Seq, time.Since(rtt)) fmt.Printf("%d bytes from %s: seq=%d time=%s\n", len(r.Data), address, r.Seq, time.Since(rtt))
//log.Printf("Received: %v", r.Data)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
} }

View File

@ -8,7 +8,7 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
pb "grpc-ping/ping" pb "lume-grpc/ping"
) )
const ( const (
@ -28,8 +28,7 @@ func Reverse(s string) string {
} }
func (s *server) Ping(ctx context.Context, req *pb.PingRequest) (*pb.PingResponse, error) { func (s *server) Ping(ctx context.Context, req *pb.PingRequest) (*pb.PingResponse, error) {
log.Printf("Received: %v seq=%d", req.Data, req.Seq) log.Printf("Received: %v", req.Data)
log.Printf("Sent: %v seq=%d", Reverse(req.Data), req.Seq)
return &pb.PingResponse{Data: Reverse(req.Data), Seq: req.Seq}, nil return &pb.PingResponse{Data: Reverse(req.Data), Seq: req.Seq}, nil
} }