|
| 1 | +# net/textprotoのPipelineサンプル |
| 2 | + |
| 3 | +[net/textproto ](https://pkg.go.dev/net/[email protected]) パッケージは、テキストプロトコルを扱う通信処理を処理しやすくするパッケージ。 |
| 4 | + |
| 5 | +> Package textproto implements generic support for text-based request/response protocols in the style of HTTP, NNTP, and SMTP. |
| 6 | +
|
| 7 | +> (textprotoパッケージは、HTTP、NNTP、SMTPスタイルのテキストベースのリクエスト/レスポンスプロトコルの汎用サポートを実装します。) |
| 8 | +
|
| 9 | +textprotoパッケージにはパイプラインという仕組みがあり、これを利用すると順序保証した状態で送受信を行うことが出来る。 |
| 10 | + |
| 11 | +一連のシーケンスを連続して送信したりする場合に有効。 |
| 12 | + |
| 13 | +# 実行 |
| 14 | + |
| 15 | +先に「ターミナル2」を起動しておき、その後に「ターミナル1」を実行。 |
| 16 | + |
| 17 | +## ターミナル1 |
| 18 | + |
| 19 | +```sh |
| 20 | +$ task |
| 21 | +task: [build] go build -o app . |
| 22 | +task: [run] ./app -server & |
| 23 | +task: [run] sleep 1 |
| 24 | +task: [run] ./app |
| 25 | +< ADD 480635715 |
| 26 | +< ADD 480686755 |
| 27 | +< ADD 480707125 |
| 28 | +< ADD 480717295 |
| 29 | +< ADD 480732305 |
| 30 | +200 ADDED 480635715 |
| 31 | +200 ADDED 480686755 |
| 32 | +200 ADDED 480707125 |
| 33 | +200 ADDED 480717295 |
| 34 | +200 ADDED 480732305 |
| 35 | +< TOTAL |
| 36 | +200 2403479195 |
| 37 | +< QUIT |
| 38 | +200 BYE |
| 39 | +``` |
| 40 | + |
| 41 | +## ターミナル2 |
| 42 | + |
| 43 | +```sh |
| 44 | +$ task watch |
| 45 | +task: [watch] sudo tcpdump -i lo -n 'tcp port 8888' -S -X |
| 46 | +tcpdump: verbose output suppressed, use -v[v]... for full protocol decode |
| 47 | +listening on lo, link-type EN10MB (Ethernet), snapshot length 262144 bytes |
| 48 | +07:24:23.117926 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [S], seq 3699364872, win 43690, options [mss 65495,sackOK,TS val 3360604880 ecr 0,nop,wscale 7], length 0 |
| 49 | + 0x0000: 4500 003c 48a8 4000 4006 f411 7f00 0001 E..<H.@.@....... |
| 50 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d408 0000 0000 ......"......... |
| 51 | + 0x0020: a002 aaaa fe30 0000 0204 ffd7 0402 080a .....0.......... |
| 52 | + 0x0030: c84e c2d0 0000 0000 0103 0307 .N.......... |
| 53 | +07:24:23.117937 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [S.], seq 111167116, ack 3699364873, win 43690, options [mss 65495,sackOK,TS val 3360604880 ecr 3360604880,nop,wscale 7], length 0 |
| 54 | + 0x0000: 4500 003c 0000 4000 4006 3cba 7f00 0001 E..<..@.@.<..... |
| 55 | + 0x0010: 7f00 0001 22b8 98e2 06a0 468c dc7f d409 ....".....F..... |
| 56 | + 0x0020: a012 aaaa fe30 0000 0204 ffd7 0402 080a .....0.......... |
| 57 | + 0x0030: c84e c2d0 c84e c2d0 0103 0307 .N...N...... |
| 58 | +07:24:23.117946 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [.], ack 111167117, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 0 |
| 59 | + 0x0000: 4500 0034 48a9 4000 4006 f418 7f00 0001 E..4H.@.@....... |
| 60 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d409 06a0 468d ......".......F. |
| 61 | + 0x0020: 8010 0156 fe28 0000 0101 080a c84e c2d0 ...V.(.......N.. |
| 62 | + 0x0030: c84e c2d0 .N.. |
| 63 | +07:24:23.118084 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [P.], seq 3699364873:3699364888, ack 111167117, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 15 |
| 64 | + 0x0000: 4500 0043 48aa 4000 4006 f408 7f00 0001 E..CH.@.@....... |
| 65 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d409 06a0 468d ......".......F. |
| 66 | + 0x0020: 8018 0156 fe37 0000 0101 080a c84e c2d0 ...V.7.......N.. |
| 67 | + 0x0030: c84e c2d0 4144 4420 3131 3830 3334 3434 .N..ADD.11803444 |
| 68 | + 0x0040: 310d 0a 1.. |
| 69 | +07:24:23.118097 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [.], ack 3699364888, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 0 |
| 70 | + 0x0000: 4500 0034 47bb 4000 4006 f506 7f00 0001 E..4G.@.@....... |
| 71 | + 0x0010: 7f00 0001 22b8 98e2 06a0 468d dc7f d418 ....".....F..... |
| 72 | + 0x0020: 8010 0156 fe28 0000 0101 080a c84e c2d0 ...V.(.......N.. |
| 73 | + 0x0030: c84e c2d0 .N.. |
| 74 | +07:24:23.118124 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [P.], seq 3699364888:3699364903, ack 111167117, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 15 |
| 75 | + 0x0000: 4500 0043 48ab 4000 4006 f407 7f00 0001 E..CH.@.@....... |
| 76 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d418 06a0 468d ......".......F. |
| 77 | + 0x0020: 8018 0156 fe37 0000 0101 080a c84e c2d0 ...V.7.......N.. |
| 78 | + 0x0030: c84e c2d0 4144 4420 3131 3831 3034 3831 .N..ADD.11810481 |
| 79 | + 0x0040: 310d 0a 1.. |
| 80 | +07:24:23.118128 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [.], ack 3699364903, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 0 |
| 81 | + 0x0000: 4500 0034 47bc 4000 4006 f505 7f00 0001 E..4G.@.@....... |
| 82 | + 0x0010: 7f00 0001 22b8 98e2 06a0 468d dc7f d427 ....".....F....' |
| 83 | + 0x0020: 8010 0156 fe28 0000 0101 080a c84e c2d0 ...V.(.......N.. |
| 84 | + 0x0030: c84e c2d0 .N.. |
| 85 | +07:24:23.118142 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [P.], seq 3699364903:3699364918, ack 111167117, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 15 |
| 86 | + 0x0000: 4500 0043 48ac 4000 4006 f406 7f00 0001 E..CH.@.@....... |
| 87 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d427 06a0 468d ......"....'..F. |
| 88 | + 0x0020: 8018 0156 fe37 0000 0101 080a c84e c2d0 ...V.7.......N.. |
| 89 | + 0x0030: c84e c2d0 4144 4420 3131 3831 3332 3739 .N..ADD.11813279 |
| 90 | + 0x0040: 310d 0a 1.. |
| 91 | +07:24:23.118153 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [P.], seq 3699364918:3699364933, ack 111167117, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 15 |
| 92 | + 0x0000: 4500 0043 48ad 4000 4006 f405 7f00 0001 E..CH.@.@....... |
| 93 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d436 06a0 468d ......"....6..F. |
| 94 | + 0x0020: 8018 0156 fe37 0000 0101 080a c84e c2d0 ...V.7.......N.. |
| 95 | + 0x0030: c84e c2d0 4144 4420 3131 3831 3435 3039 .N..ADD.11814509 |
| 96 | + 0x0040: 310d 0a 1.. |
| 97 | +07:24:23.118154 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [P.], seq 111167117:111167130, ack 3699364903, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 13 |
| 98 | + 0x0000: 4500 0041 47bd 4000 4006 f4f7 7f00 0001 E..AG.@.@....... |
| 99 | + 0x0010: 7f00 0001 22b8 98e2 06a0 468d dc7f d427 ....".....F....' |
| 100 | + 0x0020: 8018 0156 fe35 0000 0101 080a c84e c2d0 ...V.5.......N.. |
| 101 | + 0x0030: c84e c2d0 3230 3020 5355 4343 4553 530d .N..200.SUCCESS. |
| 102 | + 0x0040: 0a . |
| 103 | +07:24:23.118167 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [.], ack 111167130, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 0 |
| 104 | + 0x0000: 4500 0034 48ae 4000 4006 f413 7f00 0001 E..4H.@.@....... |
| 105 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d445 06a0 469a ......"....E..F. |
| 106 | + 0x0020: 8010 0156 fe28 0000 0101 080a c84e c2d0 ...V.(.......N.. |
| 107 | + 0x0030: c84e c2d0 .N.. |
| 108 | +07:24:23.118170 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [P.], seq 3699364933:3699364948, ack 111167130, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 15 |
| 109 | + 0x0000: 4500 0043 48af 4000 4006 f403 7f00 0001 E..CH.@.@....... |
| 110 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d445 06a0 469a ......"....E..F. |
| 111 | + 0x0020: 8018 0156 fe37 0000 0101 080a c84e c2d0 ...V.7.......N.. |
| 112 | + 0x0030: c84e c2d0 4144 4420 3131 3831 3536 3438 .N..ADD.11815648 |
| 113 | + 0x0040: 310d 0a 1.. |
| 114 | +07:24:23.118188 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [.], ack 3699364948, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 0 |
| 115 | + 0x0000: 4500 0034 47be 4000 4006 f503 7f00 0001 E..4G.@.@....... |
| 116 | + 0x0010: 7f00 0001 22b8 98e2 06a0 469a dc7f d454 ....".....F....T |
| 117 | + 0x0020: 8010 0156 fe28 0000 0101 080a c84e c2d0 ...V.(.......N.. |
| 118 | + 0x0030: c84e c2d0 .N.. |
| 119 | +07:24:23.118203 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [P.], seq 111167130:111167143, ack 3699364948, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 13 |
| 120 | + 0x0000: 4500 0041 47bf 4000 4006 f4f5 7f00 0001 E..AG.@.@....... |
| 121 | + 0x0010: 7f00 0001 22b8 98e2 06a0 469a dc7f d454 ....".....F....T |
| 122 | + 0x0020: 8018 0156 fe35 0000 0101 080a c84e c2d0 ...V.5.......N.. |
| 123 | + 0x0030: c84e c2d0 3230 3020 5355 4343 4553 530d .N..200.SUCCESS. |
| 124 | + 0x0040: 0a . |
| 125 | +07:24:23.118220 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [P.], seq 111167143:111167156, ack 3699364948, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 13 |
| 126 | + 0x0000: 4500 0041 47c0 4000 4006 f4f4 7f00 0001 E..AG.@.@....... |
| 127 | + 0x0010: 7f00 0001 22b8 98e2 06a0 46a7 dc7f d454 ....".....F....T |
| 128 | + 0x0020: 8018 0156 fe35 0000 0101 080a c84e c2d0 ...V.5.......N.. |
| 129 | + 0x0030: c84e c2d0 3230 3020 5355 4343 4553 530d .N..200.SUCCESS. |
| 130 | + 0x0040: 0a . |
| 131 | +07:24:23.118232 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [P.], seq 111167156:111167169, ack 3699364948, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 13 |
| 132 | + 0x0000: 4500 0041 47c1 4000 4006 f4f3 7f00 0001 E..AG.@.@....... |
| 133 | + 0x0010: 7f00 0001 22b8 98e2 06a0 46b4 dc7f d454 ....".....F....T |
| 134 | + 0x0020: 8018 0156 fe35 0000 0101 080a c84e c2d0 ...V.5.......N.. |
| 135 | + 0x0030: c84e c2d0 3230 3020 5355 4343 4553 530d .N..200.SUCCESS. |
| 136 | + 0x0040: 0a . |
| 137 | +07:24:23.118244 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [P.], seq 111167169:111167182, ack 3699364948, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 13 |
| 138 | + 0x0000: 4500 0041 47c2 4000 4006 f4f2 7f00 0001 E..AG.@.@....... |
| 139 | + 0x0010: 7f00 0001 22b8 98e2 06a0 46c1 dc7f d454 ....".....F....T |
| 140 | + 0x0020: 8018 0156 fe35 0000 0101 080a c84e c2d0 ...V.5.......N.. |
| 141 | + 0x0030: c84e c2d0 3230 3020 5355 4343 4553 530d .N..200.SUCCESS. |
| 142 | + 0x0040: 0a . |
| 143 | +07:24:23.118257 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [.], ack 111167182, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 0 |
| 144 | + 0x0000: 4500 0034 48b0 4000 4006 f411 7f00 0001 E..4H.@.@....... |
| 145 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d454 06a0 46ce ......"....T..F. |
| 146 | + 0x0020: 8010 0156 fe28 0000 0101 080a c84e c2d0 ...V.(.......N.. |
| 147 | + 0x0030: c84e c2d0 .N.. |
| 148 | +07:24:23.118305 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [P.], seq 3699364948:3699364955, ack 111167182, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 7 |
| 149 | + 0x0000: 4500 003b 48b1 4000 4006 f409 7f00 0001 E..;H.@.@....... |
| 150 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d454 06a0 46ce ......"....T..F. |
| 151 | + 0x0020: 8018 0156 fe2f 0000 0101 080a c84e c2d0 ...V./.......N.. |
| 152 | + 0x0030: c84e c2d0 544f 5441 4c0d 0a .N..TOTAL.. |
| 153 | +07:24:23.118358 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [P.], seq 111167182:111167197, ack 3699364955, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 15 |
| 154 | + 0x0000: 4500 0043 47c3 4000 4006 f4ef 7f00 0001 E..CG.@.@....... |
| 155 | + 0x0010: 7f00 0001 22b8 98e2 06a0 46ce dc7f d45b ....".....F....[ |
| 156 | + 0x0020: 8018 0156 fe37 0000 0101 080a c84e c2d0 ...V.7.......N.. |
| 157 | + 0x0030: c84e c2d0 3230 3020 3539 3035 3733 3631 .N..200.59057361 |
| 158 | + 0x0040: 350d 0a 5.. |
| 159 | +07:24:23.118405 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [P.], seq 3699364955:3699364961, ack 111167197, win 342, options [nop,nop,TS val 3360604880 ecr 3360604880], length 6 |
| 160 | + 0x0000: 4500 003a 48b2 4000 4006 f409 7f00 0001 E..:H.@.@....... |
| 161 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d45b 06a0 46dd ......"....[..F. |
| 162 | + 0x0020: 8018 0156 fe2e 0000 0101 080a c84e c2d0 ...V.........N.. |
| 163 | + 0x0030: c84e c2d0 5155 4954 0d0a .N..QUIT.. |
| 164 | +07:24:23.118435 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [P.], seq 111167197:111167206, ack 3699364961, win 342, options [nop,nop,TS val 3360604881 ecr 3360604880], length 9 |
| 165 | + 0x0000: 4500 003d 47c4 4000 4006 f4f4 7f00 0001 E..=G.@.@....... |
| 166 | + 0x0010: 7f00 0001 22b8 98e2 06a0 46dd dc7f d461 ....".....F....a |
| 167 | + 0x0020: 8018 0156 fe31 0000 0101 080a c84e c2d1 ...V.1.......N.. |
| 168 | + 0x0030: c84e c2d0 3230 3020 4259 450d 0a .N..200.BYE.. |
| 169 | +07:24:23.118459 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [F.], seq 111167206, ack 3699364961, win 342, options [nop,nop,TS val 3360604881 ecr 3360604880], length 0 |
| 170 | + 0x0000: 4500 0034 47c5 4000 4006 f4fc 7f00 0001 E..4G.@.@....... |
| 171 | + 0x0010: 7f00 0001 22b8 98e2 06a0 46e6 dc7f d461 ....".....F....a |
| 172 | + 0x0020: 8011 0156 fe28 0000 0101 080a c84e c2d1 ...V.(.......N.. |
| 173 | + 0x0030: c84e c2d0 .N.. |
| 174 | +07:24:23.118518 IP 127.0.0.1.39138 > 127.0.0.1.8888: Flags [F.], seq 3699364961, ack 111167207, win 342, options [nop,nop,TS val 3360604881 ecr 3360604881], length 0 |
| 175 | + 0x0000: 4500 0034 48b3 4000 4006 f40e 7f00 0001 E..4H.@.@....... |
| 176 | + 0x0010: 7f00 0001 98e2 22b8 dc7f d461 06a0 46e7 ......"....a..F. |
| 177 | + 0x0020: 8011 0156 fe28 0000 0101 080a c84e c2d1 ...V.(.......N.. |
| 178 | + 0x0030: c84e c2d1 .N.. |
| 179 | +07:24:23.118551 IP 127.0.0.1.8888 > 127.0.0.1.39138: Flags [.], ack 3699364962, win 342, options [nop,nop,TS val 3360604881 ecr 3360604881], length 0 |
| 180 | + 0x0000: 4500 0034 47c6 4000 4006 f4fb 7f00 0001 E..4G.@.@....... |
| 181 | + 0x0010: 7f00 0001 22b8 98e2 06a0 46e7 dc7f d462 ....".....F....b |
| 182 | + 0x0020: 8010 0156 fe28 0000 0101 080a c84e c2d1 ...V.(.......N.. |
| 183 | + 0x0030: c84e c2d1 .N.. |
| 184 | +^C |
| 185 | +25 packets captured |
| 186 | +50 packets received by filter |
| 187 | +0 packets dropped by kernel |
| 188 | +``` |
0 commit comments