Last active
March 26, 2023 17:22
-
-
Save bom-d-van/1d4c16385eefb3d89d33f158c8ca77e4 to your computer and use it in GitHub Desktop.
Revisions
-
bom-d-van revised this gist
Mar 12, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # Using nc and protoc as protobuf client and server Inspiration: [Linux and Unix nc command](www.computerhope.com/unix/nc.htm) Example protobuf definition: ```proto -
bom-d-van revised this gist
Mar 12, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,8 @@ protoc --encode=Person \ name: "John Doe" email: "[email protected]" id: 43 phone {number: "1010"} phone {number: "0101"} ' \ | nc 127.0.0.1 8080 ``` -
bom-d-van revised this gist
Mar 12, 2017 . 1 changed file with 19 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -39,19 +39,35 @@ protoc --encode=Person \ ## Listening on 127.0.0.1:8080 for a TCP protobuf request ```sh nc -l -p 8080 -c \ | protoc --decode=Person foo.proto ``` ## Server/Client in action sever: ```sh protoc --encode=Person \ foo.proto <<<' name: "John Doe" email: "[email protected]" id: 42 ' \ | nc -l -p 8080 -c \ | protoc --decode=Person foo.proto ``` client: ```sh protoc --encode=Person \ foo.proto <<<' name: "John Doe" email: "[email protected]" id: 43 phone {number: "1010"} ' \ | nc 127.0.0.1 8080 \ | protoc --decode=Person foo.proto ``` -
bom-d-van created this gist
Mar 12, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ # Using nc and protoc as protobuf client and server Example protobuf definition: ```proto message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; } repeated PhoneNumber phone = 4; } ``` ## Send a protobuf TCP request to 127.0.0.1:8080 ```sh protoc --encode=Person \ foo.proto <<<' name: "John Doe" email: "[email protected]" id: 43 phone {number: "1010"} phone {number: "0101"} ' \ | nc 127.0.0.1 8080 ``` ## Listening on 127.0.0.1:8080 for a TCP protobuf request ```sh nc -l -p 8080 -c | protoc --decode=Person foo.proto ``` ## Server/Client in action sever: ```sh protoc --encode=Person foo.proto <<<'name: "John Doe" email: "[email protected]" id: 42' | nc -l -p 8080 -c | protoc --decode=Person foo.proto ``` client: ```sh protoc --encode=Person foo.proto <<<'name: "John Doe" email: "[email protected]" id: 43 phone {number: "1010"}' | nc 127.0.0.1 8080 | protoc --decode=Person foo.proto ```