Compare commits
	
		
			4 Commits
		
	
	
		
			1f354bf71e
			...
			bfcaba33ab
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| bfcaba33ab | |||
| 7a30b9a5d3 | |||
| d1cc4531aa | |||
| ccad553910 | 
| @@ -25,7 +25,7 @@ type PingRequest struct { | ||||
| 	sizeCache     protoimpl.SizeCache | ||||
| 	unknownFields protoimpl.UnknownFields | ||||
|  | ||||
| 	Seq  uint32 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,omitempty"` | ||||
| 	Seq  uint64 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,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} | ||||
| } | ||||
|  | ||||
| func (x *PingRequest) GetSeq() uint32 { | ||||
| func (x *PingRequest) GetSeq() uint64 { | ||||
| 	if x != nil { | ||||
| 		return x.Seq | ||||
| 	} | ||||
| @@ -80,7 +80,7 @@ type PingResponse struct { | ||||
| 	sizeCache     protoimpl.SizeCache | ||||
| 	unknownFields protoimpl.UnknownFields | ||||
|  | ||||
| 	Seq  uint32 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,omitempty"` | ||||
| 	Seq  uint64 `protobuf:"varint,1,opt,name=seq,proto3" json:"seq,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} | ||||
| } | ||||
|  | ||||
| func (x *PingResponse) GetSeq() uint32 { | ||||
| func (x *PingResponse) GetSeq() uint64 { | ||||
| 	if x != nil { | ||||
| 		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, | ||||
| 	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, | ||||
| 	0x01, 0x28, 0x0d, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, | ||||
| 	0x01, 0x28, 0x04, 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, | ||||
| 	0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, | ||||
| 	0x73, 0x65, 0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x12, | ||||
| 	0x73, 0x65, 0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 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, 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, | ||||
| 	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, 0x6c, | ||||
| 	0x75, 0x6d, 0x65, 0x2d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, | ||||
| 	0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x10, 0x5a, 0x0e, 0x67, | ||||
| 	0x72, 0x70, 0x63, 0x2d, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, | ||||
| 	0x72, 0x6f, 0x74, 0x6f, 0x33, | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| syntax = "proto3"; | ||||
|  | ||||
| option go_package = "lume-grpc/ping"; | ||||
| option go_package = "grpc-ping/ping"; | ||||
|  | ||||
| package ping; | ||||
|  | ||||
| @@ -9,11 +9,11 @@ service ping { | ||||
| } | ||||
|  | ||||
| message PingRequest { | ||||
|     uint32 seq  = 1; | ||||
|     uint64 seq  = 1; | ||||
|     string data = 2; | ||||
| } | ||||
|  | ||||
| message PingResponse { | ||||
|     uint32 seq  = 1; | ||||
|     uint64 seq  = 1; | ||||
|     string data = 2; | ||||
| } | ||||
|   | ||||
| @@ -9,7 +9,7 @@ import ( | ||||
|  | ||||
| 	"google.golang.org/grpc" | ||||
|  | ||||
| 	pb "lume-grpc/ping" | ||||
| 	pb "grpc-ping/ping" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| @@ -26,7 +26,7 @@ func genPayload(s int) string { | ||||
| } | ||||
|  | ||||
| func main() { | ||||
| 	var i uint32 | ||||
| 	var i uint64 | ||||
| 	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||||
| 	defer cancel() | ||||
|  | ||||
| @@ -43,16 +43,14 @@ func main() { | ||||
|  | ||||
| 	for i = 1; ; i++ { | ||||
| 		rtt := time.Now() | ||||
| 		ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) | ||||
| 		ctx, cancel = context.WithTimeout(context.Background(), time.Second) | ||||
| 		r, err := c.Ping(ctx, &pb.PingRequest{Data: data, Seq: i}) | ||||
| 		if err != nil { | ||||
| 			log.Printf("could not connect to: %v", err) | ||||
| 			time.Sleep(1 * time.Second) | ||||
| 			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)) | ||||
| 		//log.Printf("Received: %v", r.Data) | ||||
| 		time.Sleep(1 * time.Second) | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -8,7 +8,7 @@ import ( | ||||
| 	"google.golang.org/grpc" | ||||
| 	"google.golang.org/grpc/reflection" | ||||
|  | ||||
| 	pb "lume-grpc/ping" | ||||
| 	pb "grpc-ping/ping" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| @@ -28,7 +28,8 @@ func Reverse(s string) string { | ||||
| } | ||||
|  | ||||
| func (s *server) Ping(ctx context.Context, req *pb.PingRequest) (*pb.PingResponse, error) { | ||||
| 	log.Printf("Received: %v", req.Data) | ||||
| 	log.Printf("Received: %v seq=%d", req.Data, req.Seq) | ||||
| 	log.Printf("Sent: %v seq=%d", Reverse(req.Data), req.Seq) | ||||
| 	return &pb.PingResponse{Data: Reverse(req.Data), Seq: req.Seq}, nil | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user