结论:
1. tcp 是流式传输协议,“流(stream)”的 含义 像河流 一样,包和包之间紧紧相互挨着,内核协议栈(tcp)不会使用特殊分隔符分割,实质上它也根本不关心这些流里边具体都是什么数据,长度是多大。
2. tcp包头中没有关于长度的字段,这个 和它 流 的特点是相匹配的。
3. tcpdump 抓到的包是ip包,大小是由ip包的length决定的。所以抓到一个length=13032的包是正常的。
tcp抓包实验
背景:
jmeter 开启多个进程同时发送大量的websocket信息给 websocket服务端;浏览器也启动一个websocket客户端; websocket服务端收到消息后 群发/单发 ,浏览器作为群里的一员,也可以收到消息。
浏览器收到消息的截图如下:
在websocket服务器上 执行:tcpdump -XAns 4096 -iany port 8282
注意‘’4096“ 含义是 如果这个包 比4096字节大,就截取到4096字节,后面的丢掉不显示。
02:32:58.473129 IP 192.168.0.236.8282 > 192.168.0.103.49644: Flags [.], seq 3513134:3526166, ack 1, win 235, options [nop,nop,TS val 5193856 ecr 930117219], length 130320x0000: 4500 331c 6d52 4000 4006 17e6 c0a8 00ec E.3.mR@.@.......0x0010: c0a8 0067 205a c1ec 8a62 3dcd 22d1 7d5d ...g.Z...b=.".}]0x0020: 8010 00eb b5b2 0000 0101 080a 004f 4080 .............O@.0x0030: 3770 7663 a7e3 8082 e597 af48 454c 4c4f 7pvc.......HELLO0x0040: 3139 3939 310d 0a81 7e00 bd37 6630 3030 19991...~..7f0000x0050: 3030 3130 6235 3630 3030 3030 3033 3820 0010b5600000038.0x0060: 7361 6964 20e4 bda0 e5a5 bde5 9388 efbc said............0x0070: 8ce7 a6bb e6ac a2e8 bf8e efbc 8ce8 bf99 ................0x0080: e4b8 aae6 b688 e681 afe5 be88 e995 bfef ................0x0090: bc8c e6a8 a1e6 8b9f e4ba 86e5 b9b3 e59d ................0x00a0: 87e7 9a84 20e6 b688 e681 afe7 9a84 e995 ................0x00b0: bfef bc8c e59b a0e4 b8ba e6b6 88e6 81af ................0x00c0: e4bc 9ae8 a2ab e590 88e5 b9b6 e58f 91e9 ................0x00d0: 8081 e591 80ef bc8c e8bf 99e6 98af e693 ................0x00e0: 8de4 bd9c e7b3 bbe7 bb9f e68e a7e5 88b6 ................0x00f0: e79a 84e5 90a7 e380 82e5 97af 4845 4c4c ............HELL0x0100: 4f31 3939 3932 0d0a 817e 00bd 3766 3030 O19992...~..7f000x0110: 3030 3031 3062 3536 3030 3030 3030 3338 00010b56000000380x0120: 2073 6169 6420 e4bd a0e5 a5bd e593 88ef .said...........0x0130: bc8c e7a6 bbe6 aca2 e8bf 8eef bc8c e8bf ................0x0140: 99e4 b8aa e6b6 88e6 81af e5be 88e9 95bf ................0x0150: efbc 8ce6 a8a1 e68b 9fe4 ba86 e5b9 b3e5 ................0x0160: 9d87 e79a 8420 e6b6 88e6 81af e79a 84e9 ................0x0170: 95bf efbc 8ce5 9ba0 e4b8 bae6 b688 e681 ................0x0180: afe4 bc9a e8a2 abe5 9088 e5b9 b6e5 8f91 ................0x0190: e980 81e5 9180 efbc 8ce8 bf99 e698 afe6 ................0x01a0: 938d e4bd 9ce7 b3bb e7bb 9fe6 8ea7 e588 ................0x01b0: b6e7 9a84 e590 a7e3 8082 e597 af48 454c .............HEL0x01c0: 4c4f 3139 3939 330d 0a81 7e00 bd37 6630 LO19993...~..7f00x01d0: 3030 3030 3130 6235 3630 3030 3030 3033 000010b5600000030x01e0: 3820 7361 6964 20e4 bda0 e5a5 bde5 9388 8.said..........0x01f0: efbc 8ce7 a6bb e6ac a2e8 bf8e efbc 8ce8 ................0x0200: bf99 e4b8 aae6 b688 e681 afe5 be88 e995 ................0x0210: bfef bc8c e6a8 a1e6 8b9f e4ba 86e5 b9b3 ................0x0220: e59d 87e7 9a84 20e6 b688 e681 afe7 9a84 ................0x0230: e995 bfef bc8c e59b a0e4 b8ba e6b6 88e6 ................0x0240: 81af e4bc 9ae8 a2ab e590 88e5 b9b6 e58f ................0x0250: 91e9 8081 e591 80ef bc8c e8bf 99e6 98af ................0x0260: e693 8de4 bd9c e7b3 bbe7 bb9f e68e a7e5 ................0x0270: 88b6 e79a 84e5 90a7 e380 82e5 97af 4845 ..............HE0x0280: 4c4c 4f31 3939 3934 0d0a 817e 00bd 3766 LLO19994...~..7f0x0290: 3030 3030 3031 3062 3536 3030 3030 3030 0000010b560000000x02a0: 3338 2073 6169 6420 e4bd a0e5 a5bd e593 38.said.........0x02b0: 88ef bc8c e7a6 bbe6 aca2 e8bf 8eef bc8c ................0x02c0: e8bf 99e4 b8aa e6b6 88e6 81af e5be 88e9 ................0x02d0: 95bf efbc 8ce6 a8a1 e68b 9fe4 ba86 e5b9 ................0x02e0: b3e5 9d87 e79a 8420 e6b6 88e6 81af e79a ................0x02f0: 84e9 95bf efbc 8ce5 9ba0 e4b8 bae6 b688 ................0x0300: e681 afe4 bc9a e8a2 abe5 9088 e5b9 b6e5 ................0x0310: 8f91 e980 81e5 9180 efbc 8ce8 bf99 e698 ................0x0320: afe6 938d e4bd 9ce7 b3bb e7bb 9fe6 8ea7 ................0x0330: e588 b6e7 9a84 e590 a7e3 8082 e597 af48 ...............H0x0340: 454c 4c4f 3139 3939 350d 0a81 7e00 bd37 ELLO19995...~..70x0350: 6630 3030 3030 3130 6235 3630 3030 3030 f0000010b56000000x0360: 3033 3820 7361 6964 20e4 bda0 e5a5 bde5 038.said........0x0370: 9388 efbc 8ce7 a6bb e6ac a2e8 bf8e efbc ................0x0380: 8ce8 bf99 e4b8 aae6 b688 e681 afe5 be88 ................0x0390: e995 bfef bc8c e6a8 a1e6 8b9f e4ba 86e5 ................0x03a0: b9b3 e59d 87e7 9a84 20e6 b688 e681 afe7 ................0x03b0: 9a84 e995 bfef bc8c e59b a0e4 b8ba e6b6 ................0x03c0: 88e6 81af e4bc 9ae8 a2ab e590 88e5 b9b6 ................0x03d0: e58f 91e9 8081 e591 80ef bc8c e8bf 99e6 ................0x03e0: 98af e693 8de4 bd9c e7b3 bbe7 bb9f e68e ................0x03f0: a7e5 88b6 e79a 84e5 90a7 e380 82e5 97af ................0x0400: 4845 4c4c 4f31 3939 3936 0d0a 817e 00bd HELLO19996...~..0x0410: 3766 3030 3030 3031 3062 3536 3030 3030 7f0000010b5600000x0420: 3030 3338 2073 6169 6420 e4bd a0e5 a5bd 0038.said.......0x0430: e593 88ef bc8c e7a6 bbe6 aca2 e8bf 8eef ................0x0440: bc8c e8bf 99e4 b8aa e6b6 88e6 81af e5be ................0x0450: 88e9 95bf efbc 8ce6 a8a1 e68b 9fe4 ba86 ................0x0460: e5b9 b3e5 9d87 e79a 8420 e6b6 88e6 81af ................0x0470: e79a 84e9 95bf efbc 8ce5 9ba0 e4b8 bae6 ................0x0480: b688 e681 afe4 bc9a e8a2 abe5 9088 e5b9 ................0x0490: b6e5 8f91 e980 81e5 9180 efbc 8ce8 bf99 ................0x04a0: e698 afe6 938d e4bd 9ce7 b3bb e7bb 9fe6 ................0x04b0: 8ea7 e588 b6e7 9a84 e590 a7e3 8082 e597 ................0x04c0: af48 454c 4c4f 3139 3939 370d 0a81 7e00 .HELLO19997...~.0x04d0: bd37 6630 3030 3030 3130 6235 3630 3030 .7f0000010b560000x04e0: 3030 3033 3820 7361 6964 20e4 bda0 e5a5 00038.said......0x04f0: bde5 9388 efbc 8ce7 a6bb e6ac a2e8 bf8e ................0x0500: efbc 8ce8 bf99 e4b8 aae6 b688 e681 afe5 ................0x0510: be88 e995 bfef bc8c e6a8 a1e6 8b9f e4ba ................0x0520: 86e5 b9b3 e59d 87e7 9a84 20e6 b688 e681 ................0x0530: afe7 9a84 e995 bfef bc8c e59b a0e4 b8ba ................0x0540: e6b6 88e6 81af e4bc 9ae8 a2ab e590 88e5 ................0x0550: b9b6 e58f 91e9 8081 e591 80ef bc8c e8bf ................0x0560: 99e6 98af e693 8de4 bd9c e7b3 bbe7 bb9f ................0x0570: e68e a7e5 88b6 e79a 84e5 90a7 e380 82e5 ................0x0580: 97af 4845 4c4c 4f31 3939 3938 0d0a 817e ..HELLO19998...~0x0590: 00bd 3766 3030 3030 3031 3062 3536 3030 ..7f0000010b56000x05a0: 3030 3030 3338 2073 6169 6420 e4bd a0e5 000038.said.....0x05b0: a5bd e593 88ef bc8c e7a6 bbe6 aca2 e8bf ................0x05c0: 8eef bc8c e8bf 99e4 b8aa e6b6 88e6 81af ................0x05d0: e5be 88e9 95bf efbc 8ce6 a8a1 e68b 9fe4 ................0x05e0: ba86 e5b9 b3e5 9d87 e79a 8420 e6b6 88e6 ................0x05f0: 81af e79a 84e9 95bf efbc 8ce5 9ba0 e4b8 ................0x0600: bae6 b688 e681 afe4 bc9a e8a2 abe5 9088 ................0x0610: e5b9 b6e5 8f91 e980 81e5 9180 efbc 8ce8 ................0x0620: bf99 e698 afe6 938d e4bd 9ce7 b3bb e7bb ................0x0630: 9fe6 8ea7 e588 b6e7 9a84 e590 a7e3 8082 ................0x0640: e597 af48 454c 4c4f 3139 3939 390d 0a81 ...HELLO19999...0x0650: 7e00 bd37 6630 3030 3030 3130 6235 3630 ~..7f0000010b5600x0660: 3030 3030 3033 3820 7361 6964 20e4 bda0 0000038.said....0x0670: e5a5 bde5 9388 efbc 8ce7 a6bb e6ac a2e8 ................0x0680: bf8e efbc 8ce8 bf99 e4b8 aae6 b688 e681 ................0x0690: afe5 be88 e995 bfef bc8c e6a8 a1e6 8b9f ................0x06a0: e4ba 86e5 b9b3 e59d 87e7 9a84 20e6 b688 ................0x06b0: e681 afe7 9a84 e995 bfef bc8c e59b a0e4 ................0x06c0: b8ba e6b6 88e6 81af e4bc 9ae8 a2ab e590 ................0x06d0: 88e5 b9b6 e58f 91e9 8081 e591 80ef bc8c ................0x06e0: e8bf 99e6 98af e693 8de4 bd9c e7b3 bbe7 ................0x06f0: bb9f e68e a7e5 88b6 e79a 84e5 90a7 e380 ................0x0700: 82e5 97af 4845 4c4c 4f32 3030 3030 0d0a ....HELLO20000..0x0710: 817e 00bd 3766 3030 3030 3031 3062 3535 .~..7f0000010b550x0720: 3030 3030 3030 3233 2073 6169 6420 e4bd 00000023.said...0x0730: a0e5 a5bd e593 88ef bc8c e7a6 bbe6 aca2 ................0x0740: e8bf 8eef bc8c e8bf 99e4 b8aa e6b6 88e6 ................0x0750: 81af e5be 88e9 95bf efbc 8ce6 a8a1 e68b ................0x0760: 9fe4 ba86 e5b9 b3e5 9d87 e79a 8420 e6b6 ................0x0770: 88e6 81af e79a 84e9 95bf efbc 8ce5 9ba0 ................0x0780: e4b8 bae6 b688 e681 afe4 bc9a e8a2 abe5 ................0x0790: 9088 e5b9 b6e5 8f91 e980 81e5 9180 efbc ................0x07a0: 8ce8 bf99 e698 afe6 938d e4bd 9ce7 b3bb ................0x07b0: e7bb 9fe6 8ea7 e588 b6e7 9a84 e590 a7e3 ................0x07c0: 8082 e597 af48 454c 4c4f 3132 3335 350d .....HELLO12355.0x07d0: 0a81 7e00 bd37 6630 3030 3030 3130 6235 ..~..7f0000010b50x07e0: 3530 3030 3030 3032 3320 7361 6964 20e4 500000023.said..0x07f0: bda0 e5a5 bde5 9388 efbc 8ce7 a6bb e6ac ................0x0800: a2e8 bf8e efbc 8ce8 bf99 e4b8 aae6 b688 ................0x0810: e681 afe5 be88 e995 bfef bc8c e6a8 a1e6 ................0x0820: 8b9f e4ba 86e5 b9b3 e59d 87e7 9a84 20e6 ................0x0830: b688 e681 afe7 9a84 e995 bfef bc8c e59b ................0x0840: a0e4 b8ba e6b6 88e6 81af e4bc 9ae8 a2ab ................0x0850: e590 88e5 b9b6 e58f 91e9 8081 e591 80ef ................0x0860: bc8c e8bf 99e6 98af e693 8de4 bd9c e7b3 ................0x0870: bbe7 bb9f e68e a7e5 88b6 e79a 84e5 90a7 ................0x0880: e380 82e5 97af 4845 4c4c 4f31 3233 3536 ......HELLO123560x0890: 0d0a 817e 00bd 3766 3030 3030 3031 3062 ...~..7f0000010b0x08a0: 3535 3030 3030 3030 3233 2073 6169 6420 5500000023.said.0x08b0: e4bd a0e5 a5bd e593 88ef bc8c e7a6 bbe6 ................0x08c0: aca2 e8bf 8eef bc8c e8bf 99e4 b8aa e6b6 ................0x08d0: 88e6 81af e5be 88e9 95bf efbc 8ce6 a8a1 ................0x08e0: e68b 9fe4 ba86 e5b9 b3e5 9d87 e79a 8420 ................0x08f0: e6b6 88e6 81af e79a 84e9 95bf efbc 8ce5 ................0x0900: 9ba0 e4b8 bae6 b688 e681 afe4 bc9a e8a2 ................0x0910: abe5 9088 e5b9 b6e5 8f91 e980 81e5 9180 ................0x0920: efbc 8ce8 bf99 e698 afe6 938d e4bd 9ce7 ................0x0930: b3bb e7bb 9fe6 8ea7 e588 b6e7 9a84 e590 ................0x0940: a7e3 8082 e597 af48 454c 4c4f 3132 3335 .......HELLO12350x0950: 370d 0a81 7e00 bd37 6630 3030 3030 3130 7...~..7f00000100x0960: 6235 3530 3030 3030 3032 3320 7361 6964 b5500000023.said0x0970: 20e4 bda0 e5a5 bde5 9388 efbc 8ce7 a6bb ................0x0980: e6ac a2e8 bf8e efbc 8ce8 bf99 e4b8 aae6 ................0x0990: b688 e681 afe5 be88 e995 bfef bc8c e6a8 ................0x09a0: a1e6 8b9f e4ba 86e5 b9b3 e59d 87e7 9a84 ................0x09b0: 20e6 b688 e681 afe7 9a84 e995 bfef bc8c ................0x09c0: e59b a0e4 b8ba e6b6 88e6 81af e4bc 9ae8 ................0x09d0: a2ab e590 88e5 b9b6 e58f 91e9 8081 e591 ................0x09e0: 80ef bc8c e8bf 99e6 98af e693 8de4 bd9c ................0x09f0: e7b3 bbe7 bb9f e68e a7e5 88b6 e79a 84e5 ................0x0a00: 90a7 e380 82e5 97af 4845 4c4c 4f31 3233 ........HELLO1230x0a10: 3538 0d0a 817e 00bd 3766 3030 3030 3031 58...~..7f0000010x0a20: 3062 3535 3030 3030 3030 3233 2073 6169 0b5500000023.sai0x0a30: 6420 e4bd a0e5 a5bd e593 88ef bc8c e7a6 d...............0x0a40: bbe6 aca2 e8bf 8eef bc8c e8bf 99e4 b8aa ................0x0a50: e6b6 88e6 81af e5be 88e9 95bf efbc 8ce6 ................0x0a60: a8a1 e68b 9fe4 ba86 e5b9 b3e5 9d87 e79a ................0x0a70: 8420 e6b6 88e6 81af e79a 84e9 95bf efbc ................0x0a80: 8ce5 9ba0 e4b8 bae6 b688 e681 afe4 bc9a ................0x0a90: e8a2 abe5 9088 e5b9 b6e5 8f91 e980 81e5 ................0x0aa0: 9180 efbc 8ce8 bf99 e698 afe6 938d e4bd ................0x0ab0: 9ce7 b3bb e7bb 9fe6 8ea7 e588 b6e7 9a84 ................0x0ac0: e590 a7e3 8082 e597 af48 454c 4c4f 3132 .........HELLO120x0ad0: 3335 390d 0a81 7e00 bd37 6630 3030 3030 359...~..7f000000x0ae0: 3130 6235 3530 3030 3030 3032 3320 7361 10b5500000023.sa0x0af0: 6964 20e4 bda0 e5a5 bde5 9388 efbc 8ce7 id..............0x0b00: a6bb e6ac a2e8 bf8e efbc 8ce8 bf99 e4b8 ................0x0b10: aae6 b688 e681 afe5 be88 e995 bfef bc8c ................0x0b20: e6a8 a1e6 8b9f e4ba 86e5 b9b3 e59d 87e7 ................0x0b30: 9a84 20e6 b688 e681 afe7 9a84 e995 bfef ................0x0b40: bc8c e59b a0e4 b8ba e6b6 88e6 81af e4bc ................0x0b50: 9ae8 a2ab e590 88e5 b9b6 e58f 91e9 8081 ................0x0b60: e591 80ef bc8c e8bf 99e6 98af e693 8de4 ................0x0b70: bd9c e7b3 bbe7 bb9f e68e a7e5 88b6 e79a ................0x0b80: 84e5 90a7 e380 82e5 97af 4845 4c4c 4f31 ..........HELLO10x0b90: 3233 3630 0d0a 817e 00bd 3766 3030 3030 2360...~..7f00000x0ba0: 3031 3062 3535 3030 3030 3030 3233 2073 010b5500000023.s0x0bb0: 6169 6420 e4bd a0e5 a5bd e593 88ef bc8c aid.............0x0bc0: e7a6 bbe6 aca2 e8bf 8eef bc8c e8bf 99e4 ................0x0bd0: b8aa e6b6 88e6 81af e5be 88e9 95bf efbc ................0x0be0: 8ce6 a8a1 e68b 9fe4 ba86 e5b9 b3e5 9d87 ................0x0bf0: e79a 8420 e6b6 88e6 81af e79a 84e9 95bf ................0x0c00: efbc 8ce5 9ba0 e4b8 bae6 b688 e681 afe4 ................0x0c10: bc9a e8a2 abe5 9088 e5b9 b6e5 8f91 e980 ................0x0c20: 81e5 9180 efbc 8ce8 bf99 e698 afe6 938d ................0x0c30: e4bd 9ce7 b3bb e7bb 9fe6 8ea7 e588 b6e7 ................0x0c40: 9a84 e590 a7e3 8082 e597 af48 454c 4c4f ...........HELLO0x0c50: 3132 3336 310d 0a81 7e00 bd37 6630 3030 12361...~..7f0000x0c60: 3030 3130 6235 3530 3030 3030 3032 3320 0010b5500000023.0x0c70: 7361 6964 20e4 bda0 e5a5 bde5 9388 efbc said............0x0c80: 8ce7 a6bb e6ac a2e8 bf8e efbc 8ce8 bf99 ................0x0c90: e4b8 aae6 b688 e681 afe5 be88 e995 bfef ................0x0ca0: bc8c e6a8 a1e6 8b9f e4ba 86e5 b9b3 e59d ................0x0cb0: 87e7 9a84 20e6 b688 e681 afe7 9a84 e995 ................0x0cc0: bfef bc8c e59b a0e4 b8ba e6b6 88e6 81af ................0x0cd0: e4bc 9ae8 a2ab e590 88e5 b9b6 e58f 91e9 ................0x0ce0: 8081 e591 80ef bc8c e8bf 99e6 98af e693 ................0x0cf0: 8de4 bd9c e7b3 bbe7 bb9f e68e a7e5 88b6 ................0x0d00: e79a 84e5 90a7 e380 82e5 97af 4845 4c4c ............HELL0x0d10: 4f31 3233 3632 0d0a 817e 00bd 3766 3030 O12362...~..7f000x0d20: 3030 3031 3062 3535 3030 3030 3030 3233 00010b55000000230x0d30: 2073 6169 6420 e4bd a0e5 a5bd e593 88ef .said...........0x0d40: bc8c e7a6 bbe6 aca2 e8bf 8eef bc8c e8bf ................0x0d50: 99e4 b8aa e6b6 88e6 81af e5be 88e9 95bf ................0x0d60: efbc 8ce6 a8a1 e68b 9fe4 ba86 e5b9 b3e5 ................0x0d70: 9d87 e79a 8420 e6b6 88e6 81af e79a 84e9 ................0x0d80: 95bf efbc 8ce5 9ba0 e4b8 bae6 b688 e681 ................0x0d90: afe4 bc9a e8a2 abe5 9088 e5b9 b6e5 8f91 ................0x0da0: e980 81e5 9180 efbc 8ce8 bf99 e698 afe6 ................0x0db0: 938d e4bd 9ce7 b3bb e7bb 9fe6 8ea7 e588 ................0x0dc0: b6e7 9a84 e590 a7e3 8082 e597 af48 454c .............HEL0x0dd0: 4c4f 3132 3336 330d 0a81 7e00 bd37 6630 LO12363...~..7f00x0de0: 3030 3030 3130 6235 3530 3030 3030 3032 000010b5500000020x0df0: 3320 7361 6964 20e4 bda0 e5a5 bde5 9388 3.said..........0x0e00: efbc 8ce7 a6bb e6ac a2e8 bf8e efbc 8ce8 ................0x0e10: bf99 e4b8 aae6 b688 e681 afe5 be88 e995 ................0x0e20: bfef bc8c e6a8 a1e6 8b9f e4ba 86e5 b9b3 ................0x0e30: e59d 87e7 9a84 20e6 b688 e681 afe7 9a84 ................0x0e40: e995 bfef bc8c e59b a0e4 b8ba e6b6 88e6 ................0x0e50: 81af e4bc 9ae8 a2ab e590 88e5 b9b6 e58f ................0x0e60: 91e9 8081 e591 80ef bc8c e8bf 99e6 98af ................0x0e70: e693 8de4 bd9c e7b3 bbe7 bb9f e68e a7e5 ................0x0e80: 88b6 e79a 84e5 90a7 e380 82e5 97af 4845 ..............HE0x0e90: 4c4c 4f31 3233 3634 0d0a 817e 00bd 3766 LLO12364...~..7f0x0ea0: 3030 3030 3031 3062 3535 3030 3030 3030 0000010b550000000x0eb0: 3233 2073 6169 6420 e4bd a0e5 a5bd e593 23.said.........0x0ec0: 88ef bc8c e7a6 bbe6 aca2 e8bf 8eef bc8c ................0x0ed0: e8bf 99e4 b8aa e6b6 88e6 81af e5be 88e9 ................0x0ee0: 95bf efbc 8ce6 a8a1 e68b 9fe4 ba86 e5b9 ................0x0ef0: b3e5 9d87 e79a 8420 e6b6 88e6 81af e79a ................0x0f00: 84e9 95bf efbc 8ce5 9ba0 e4b8 bae6 b688 ................0x0f10: e681 afe4 bc9a e8a2 abe5 9088 e5b9 b6e5 ................0x0f20: 8f91 e980 81e5 9180 efbc 8ce8 bf99 e698 ................0x0f30: afe6 938d e4bd 9ce7 b3bb e7bb 9fe6 8ea7 ................0x0f40: e588 b6e7 9a84 e590 a7e3 8082 e597 af48 ...............H0x0f50: 454c 4c4f 3132 3336 350d 0a81 7e00 bd37 ELLO12365...~..70x0f60: 6630 3030 3030 3130 6235 3530 3030 3030 f0000010b55000000x0f70: 3032 3320 7361 6964 20e4 bda0 e5a5 bde5 023.said........0x0f80: 9388 efbc 8ce7 a6bb e6ac a2e8 bf8e efbc ................0x0f90: 8ce8 bf99 e4b8 aae6 b688 e681 afe5 be88 ................0x0fa0: e995 bfef bc8c e6a8 a1e6 8b9f e4ba 86e5 ................0x0fb0: b9b3 e59d 87e7 9a84 20e6 b688 e681 afe7 ................0x0fc0: 9a84 e995 bfef bc8c e59b a0e4 b8ba e6b6 ................0x0fd0: 88e6 81af e4bc 9ae8 a2ab e590 88e5 b9b6 ................0x0fe0: e58f 91e9 8081 e591 80ef bc8c e8bf 99e6 ................
02:32:58.473300 IP 192.168.0.236.8282 > 192.168.0.103.49644: Flags [P.], seq 3526166:3527814, ack 1, win 235, options [nop,nop,TS val 5193857 ecr 930117219], length 16480x0000: 4500 06a4 6d5b 4000 4006 4455 c0a8 00ec E...m[@.@.DU....0x0010: c0a8 0067 205a c1ec 8a62 70b5 22d1 7d5d ...g.Z...bp.".}]0x0020: 8018 00eb 893a 0000 0101 080a 004f 4081 .....:.......O@.0x0030: 3770 7663 ba86 e5b9 b3e5 9d87 e79a 8420 7pvc............0x0040: e6b6 88e6 81af e79a 84e9 95bf efbc 8ce5 ................0x0050: 9ba0 e4b8 bae6 b688 e681 afe4 bc9a e8a2 ................0x0060: abe5 9088 e5b9 b6e5 8f91 e980 81e5 9180 ................0x0070: efbc 8ce8 bf99 e698 afe6 938d e4bd 9ce7 ................0x0080: b3bb e7bb 9fe6 8ea7 e588 b6e7 9a84 e590 ................0x0090: a7e3 8082 e597 af48 454c 4c4f 3134 3233 .......HELLO14230x00a0: 350d 0a81 7e00 bd37 6630 3030 3030 3130 5...~..7f00000100x00b0: 6235 3430 3030 3030 3032 3520 7361 6964 b5400000025.said0x00c0: 20e4 bda0 e5a5 bde5 9388 efbc 8ce7 a6bb ................0x00d0: e6ac a2e8 bf8e efbc 8ce8 bf99 e4b8 aae6 ................0x00e0: b688 e681 afe5 be88 e995 bfef bc8c e6a8 ................
分析包头:
02:32:58.473129 IP 192.168.0.236.8282 > 192.168.0.103.49644: Flags [.], seq 3513134:3526166, ack 1, win 235, options [nop,nop,TS val 5193856 ecr 930117219], length 130320x0000: 4500 331c 6d52 4000 4006 17e6 c0a8 00ec E.3.mR@.@....... // version=4, IHL = 20字节 , total length=331c= 13084 (ip头+data), identification= 6d52, flag_offset= 4000 (不分片), ttl= 64, protocol= 6, checksum= 17e6 ,192.168.0.2360x0010: c0a8 0067 205a c1ec 8a62 3dcd 22d1 7d5d ...g.Z...b=.".}] // 192.168.0.103 8282 49644, seq1 = 8a62 3dcd ack = 22d1 7d5d0x0020: 8010 00eb b5b2 0000 0101 080a 004f 4080 .............O@. // data offset = 8 , window = eb = 235 , checksum= b5b2 urgentPointer= 0000, options+ padding = 12字节 0x0030: 3770 7663
ip头部:
0x0000: 4500 331c 6d52 4000 4006 17e6 c0a8 00ec E.3.mR@.@.......
0x0010: c0a8 0067
共20字节(16+4):
45 // version=4 ( 4表示IPV4, 6表示IPV6) IHL = 20 (5*4,4字节为单位)
00 // Type of Service
331c // 总长度 = 13084 (ip头+data),
6d52 // Identification 标识,主机每发一个报文,加1,分片重组时会用到该字段。
4000 // 0100 0000 ; DF=1 表示不分片, MF=0 表示最后一片 ;Fragment Offset =0
4006 // ttl=64, Protocol=6 (6 TCP, 17 UDP)
17e6 //Header Checksum 首部检验和,只检验数据包的首部,不检验数据部分
c0a8 00ec // 192.168.0.236 Source Address
c0a8 0067 // 192.168.0.103 Destination Address
tcp 头部:
0x0010: xxxx xxxx 205a c1ec 8a62 3dcd 22d1 7d5d ...g.Z...b=.".}]
0x0020: 8010 00eb b5b2 0000 0101 080a 004f 4080 .............O@.
0x0030: 3770 7663
长度 32个字节 (12 + 16 + 4)
205a // 8282 Source Port
c1ec // 49644 Destination Port
8a62 3dcd // 2321694157 Sequence Number 序号字段。TCP链接中传输的数据流中每个字节都编上一个序号。序号字段的值指的是本报文段所发送的数据的第一个字节的序号
22d1 7d5d // Acknowledgment Number
8 // Data Offset tcp首部长度 32字节(8*4)
010 // 二进制 0000 0001 0000 依次是Reserved URG ACK PSH RST SYN FIN ;ACK=1
00eb // 235 Window
b5b2 // Checksum 校验字段,包括TCP首部和TCP数据
0000 // Urgent Pointer
0101 080a 004f 4080 3770 7663 // 时间戳 时间戳 padding
紧接着这个报文的头部:
02:32:58.473300 IP 192.168.0.236.8282 > 192.168.0.103.49644: Flags [P.], seq 3526166:3527814, ack 1, win 235, options [nop,nop,TS val 5193857 ecr 930117219], length 16480x0000: 4500 06a4 6d5b 4000 4006 4455 c0a8 00ec E...m[@.@.DU....0x0010: c0a8 0067 205a c1ec 8a62 70b5 22d1 7d5d ...g.Z...bp.".}] //seq2 = 8a62 70b5, ack=22d1 7d5d0x0020: 8018 00eb 893a 0000 0101 080a 004f 4081 .....:.......O@.0x0030: 3770 7663
分析:和前一个包相比:
seq2 - seq1 = 2321707189 - 2321694157 = 13032 ; 13032 是 一个tcp包中的纯数据的长度
并且这个包的 8018 // offset=32字节,后边二进制是 0000 00011000 ; 可以看出 ACK=1,PSH=1
标识接收方应该尽快将这个报文段交给应用层。接收到PSH = 1的TCP报文段,应尽快的交付接收应用进程,而不再等待整个缓存都填满了后再向上交付。
分析websocket 包
0x0710: 817e 00bd 3766 3030 3030 3031 3062 3535 .~..7f0000010b550x0720: 3030 3030 3030 3233 2073 6169 6420 e4bd 00000023.said...0x0730: a0e5 a5bd e593 88ef bc8c e7a6 bbe6 aca2 ................0x0740: e8bf 8eef bc8c e8bf 99e4 b8aa e6b6 88e6 ................0x0750: 81af e5be 88e9 95bf efbc 8ce6 a8a1 e68b ................0x0760: 9fe4 ba86 e5b9 b3e5 9d87 e79a 8420 e6b6 ................0x0770: 88e6 81af e79a 84e9 95bf efbc 8ce5 9ba0 ................0x0780: e4b8 bae6 b688 e681 afe4 bc9a e8a2 abe5 ................0x0790: 9088 e5b9 b6e5 8f91 e980 81e5 9180 efbc ................0x07a0: 8ce8 bf99 e698 afe6 938d e4bd 9ce7 b3bb ................0x07b0: e7bb 9fe6 8ea7 e588 b6e7 9a84 e590 a7e3 ................0x07c0: 8082 e597 af48 454c 4c4f 3132 3335 350d .....HELLO12355.0x07d0: 0a ..~..7f0000010b5
这个包长度:189字节 (4 + 11*16 + 9)
分析websocket 包头:
81 // 1000 0001 ;FIN=1 , opcode = 1 文本
7e // 0111 1110 ; MASK=0 , payload len= 126 ; 代表长度占2个字节
00bd // 189 字节;
所以,整个websocket头部 占4个字节
细节:0d0a 代表\r\n