tcp_rpc

command
v0.5.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2025 License: MIT Imports: 4 Imported by: 0

README

net/rpc のサンプル

net/rpc パッケージは、RPCを扱う通信処理を処理しやすくするパッケージ。

内部のエンコードには encoding/gob が利用されているため、Goアプリ専用のRPC通信となる。

サクッと、RPC通信するプログラムを作成したい場合に便利。

実行

先に「ターミナル2」を起動しておき、その後に「ターミナル1」を実行。

ターミナル1

$ task
task: [run] ./app -server &
task: [run] sleep 1
task: [run] ./app -x 2071723 -y 5363222357
2071723 * 5363222357 = 11111111111111111
task: [run] sleep 1
task: [run] pkill app

ターミナル2

$ task watch
task: [watch] sudo tcpdump -i lo -n 'tcp port 8888' -S -X
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on lo, link-type EN10MB (Ethernet), snapshot length 262144 bytes
09:33:31.610400 IP 127.0.0.1.59218 > 127.0.0.1.8888: Flags [S], seq 2540744218, win 43690, options [mss 65495,sackOK,TS val 342965887 ecr 0,nop,wscale 7], length 0
        0x0000:  4500 003c 8c51 4000 4006 b068 7f00 0001  E..<.Q@.@..h....
        0x0010:  7f00 0001 e752 22b8 9770 ae1a 0000 0000  .....R"..p......
        0x0020:  a002 aaaa fe30 0000 0204 ffd7 0402 080a  .....0..........
        0x0030:  1471 3e7f 0000 0000 0103 0307            .q>.........
09:33:31.610412 IP 127.0.0.1.8888 > 127.0.0.1.59218: Flags [S.], seq 2746200011, ack 2540744219, win 43690, options [mss 65495,sackOK,TS val 342965887 ecr 342965887,nop,wscale 7], length 0
        0x0000:  4500 003c 0000 4000 4006 3cba 7f00 0001  E..<..@.@.<.....
        0x0010:  7f00 0001 22b8 e752 a3af afcb 9770 ae1b  ...."..R.....p..
        0x0020:  a012 aaaa fe30 0000 0204 ffd7 0402 080a  .....0..........
        0x0030:  1471 3e7f 1471 3e7f 0103 0307            .q>..q>.....
09:33:31.610421 IP 127.0.0.1.59218 > 127.0.0.1.8888: Flags [.], ack 2746200012, win 342, options [nop,nop,TS val 342965887 ecr 342965887], length 0
        0x0000:  4500 0034 8c52 4000 4006 b06f 7f00 0001  E..4.R@.@..o....
        0x0010:  7f00 0001 e752 22b8 9770 ae1b a3af afcc  .....R"..p......
        0x0020:  8010 0156 fe28 0000 0101 080a 1471 3e7f  ...V.(.......q>.
        0x0030:  1471 3e7f                                .q>.
09:33:31.610557 IP 127.0.0.1.59218 > 127.0.0.1.8888: Flags [P.], seq 2540744219:2540744338, ack 2746200012, win 342, options [nop,nop,TS val 342965887 ecr 342965887], length 119
        0x0000:  4500 00ab 8c53 4000 4006 aff7 7f00 0001  E....S@.@.......
        0x0010:  7f00 0001 e752 22b8 9770 ae1b a3af afcc  .....R"..p......
        0x0020:  8018 0156 fe9f 0000 0101 080a 1471 3e7f  ...V.........q>.
        0x0030:  1471 3e7f 2e7f 0301 0107 5265 7175 6573  .q>.......Reques
        0x0040:  7401 ff80 0001 0201 0d53 6572 7669 6365  t........Service
        0x0050:  4d65 7468 6f64 010c 0001 0353 6571 0106  Method.....Seq..
        0x0060:  0000 0015 ff80 0110 5365 7276 6963 652e  ........Service.
        0x0070:  4d75 6c74 6970 6c79 0021 ff81 0301 0107  Multiply.!......
        0x0080:  5265 7175 6573 7401 ff82 0001 0201 0158  Request........X
        0x0090:  0104 0001 0159 0104 0000 000f ff82 01fd  .....Y..........
        0x00a0:  3f39 5601 fb02 7f58 8eaa 00              ?9V....X...
09:33:31.610567 IP 127.0.0.1.8888 > 127.0.0.1.59218: Flags [.], ack 2540744338, win 341, options [nop,nop,TS val 342965887 ecr 342965887], length 0
        0x0000:  4500 0034 c47a 4000 4006 7847 7f00 0001  E..4.z@.@.xG....
        0x0010:  7f00 0001 22b8 e752 a3af afcc 9770 ae92  ...."..R.....p..
        0x0020:  8010 0155 fe28 0000 0101 080a 1471 3e7f  ...U.(.......q>.
        0x0030:  1471 3e7f                                .q>.
09:33:31.610838 IP 127.0.0.1.8888 > 127.0.0.1.59218: Flags [P.], seq 2746200012:2746200139, ack 2540744338, win 342, options [nop,nop,TS val 342965888 ecr 342965887], length 127
        0x0000:  4500 00b3 c47b 4000 4006 77c7 7f00 0001  E....{@.@.w.....
        0x0010:  7f00 0001 22b8 e752 a3af afcc 9770 ae92  ...."..R.....p..
        0x0020:  8018 0156 fea7 0000 0101 080a 1471 3e80  ...V.........q>.
        0x0030:  1471 3e7f 397f 0301 0108 5265 7370 6f6e  .q>.9.....Respon
        0x0040:  7365 01ff 8000 0103 010d 5365 7276 6963  se........Servic
        0x0050:  654d 6574 686f 6401 0c00 0103 5365 7101  eMethod.....Seq.
        0x0060:  0600 0105 4572 726f 7201 0c00 0000 15ff  ....Error.......
        0x0070:  8001 1053 6572 7669 6365 2e4d 756c 7469  ...Service.Multi
        0x0080:  706c 7900 21ff 8103 0101 0852 6573 706f  ply.!......Respo
        0x0090:  6e73 6501 ff82 0001 0101 0652 6573 756c  nse........Resul
        0x00a0:  7401 0400 0000 0cff 8201 f94e f2fe 4dac  t..........N..M.
        0x00b0:  e38e 00                                  ...
09:33:31.610847 IP 127.0.0.1.59218 > 127.0.0.1.8888: Flags [.], ack 2746200139, win 342, options [nop,nop,TS val 342965888 ecr 342965888], length 0
        0x0000:  4500 0034 8c54 4000 4006 b06d 7f00 0001  E..4.T@.@..m....
        0x0010:  7f00 0001 e752 22b8 9770 ae92 a3af b04b  .....R"..p.....K
        0x0020:  8010 0156 fe28 0000 0101 080a 1471 3e80  ...V.(.......q>.
        0x0030:  1471 3e80                                .q>.
09:33:31.610967 IP 127.0.0.1.59218 > 127.0.0.1.8888: Flags [F.], seq 2540744338, ack 2746200139, win 342, options [nop,nop,TS val 342965888 ecr 342965888], length 0
        0x0000:  4500 0034 8c55 4000 4006 b06c 7f00 0001  E..4.U@.@..l....
        0x0010:  7f00 0001 e752 22b8 9770 ae92 a3af b04b  .....R"..p.....K
        0x0020:  8011 0156 fe28 0000 0101 080a 1471 3e80  ...V.(.......q>.
        0x0030:  1471 3e80                                .q>.
09:33:31.611026 IP 127.0.0.1.8888 > 127.0.0.1.59218: Flags [F.], seq 2746200139, ack 2540744339, win 342, options [nop,nop,TS val 342965888 ecr 342965888], length 0
        0x0000:  4500 0034 c47c 4000 4006 7845 7f00 0001  E..4.|@.@.xE....
        0x0010:  7f00 0001 22b8 e752 a3af b04b 9770 ae93  ...."..R...K.p..
        0x0020:  8011 0156 fe28 0000 0101 080a 1471 3e80  ...V.(.......q>.
        0x0030:  1471 3e80                                .q>.
09:33:31.611052 IP 127.0.0.1.59218 > 127.0.0.1.8888: Flags [.], ack 2746200140, win 342, options [nop,nop,TS val 342965888 ecr 342965888], length 0
        0x0000:  4500 0034 8c56 4000 4006 b06b 7f00 0001  E..4.V@.@..k....
        0x0010:  7f00 0001 e752 22b8 9770 ae93 a3af b04c  .....R"..p.....L
        0x0020:  8010 0156 fe28 0000 0101 080a 1471 3e80  ...V.(.......q>.
        0x0030:  1471 3e80                                .q>.
^C
10 packets captured
20 packets received by filter
0 packets dropped by kernel

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL