新项目开始时,有时候为了调试封包协议,则会一个字节一字节的核对

有时候也会出现,服务器说你没发,客户端说我发了你没收到…

公司有高手时,则会使用一个工具来抓包分析,比如WPE,Wireshark等等

网络封包不同于Http抓包,上手还是有些难度的,所以我搞了一个配置直接开启封包日志输出

配置文件中添加如下配置

network.log.active=true

重启服务器,再次登录…

2018-09-06 17:22:44.231 [nioEventLoopGroup-4-5] DEBUG LoggingHandler.java:239 - [id: 0x9e08b295, L:/192.168.50.40:52113 - R:/192.168.50.63:63444] READ: 8B
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 06 00 17 00 00 00 01 00                         |........        |
+--------+-------------------------------------------------+----------------+
2018-09-06 17:22:44.231 [nioEventLoopGroup-4-5] DEBUG LoggingHandler.java:247 - [id: 0x9e08b295, L:/192.168.50.40:52113 - R:/192.168.50.63:63444] WRITE: 11B
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 09 00 02 00 08 87 c7 c3 f1 da 2c                |..........,     |
+--------+-------------------------------------------------+----------------+
2018-09-06 17:22:44.232 [nioEventLoopGroup-4-5] DEBUG LoggingHandler.java:263 - [id: 0x9e08b295, L:/192.168.50.40:52113 - R:/192.168.50.63:63444] FLUSH
2018-09-06 17:22:44.232 [nioEventLoopGroup-4-5] DEBUG LoggingHandler.java:231 - [id: 0x9e08b295, L:/192.168.50.40:52113 - R:/192.168.50.63:63444] READ COMPLETE
2018-09-06 17:22:54.380 [nioEventLoopGroup-4-5] DEBUG LoggingHandler.java:239 - [id: 0x9e08b295, L:/192.168.50.40:52113 - R:/192.168.50.63:63444] READ: 8B
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 06 00 18 00 00 00 01 00                         |........        |
+--------+-------------------------------------------------+----------------+
2018-09-06 17:22:54.380 [nioEventLoopGroup-4-5] DEBUG LoggingHandler.java:247 - [id: 0x9e08b295, L:/192.168.50.40:52113 - R:/192.168.50.63:63444] WRITE: 11B
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 09 00 02 00 08 ac 96 c4 f1 da 2c                |..........,     |
+--------+-------------------------------------------------+----------------+
2018-09-06 17:22:54.380 [nioEventLoopGroup-4-5] DEBUG LoggingHandler.java:263 - [id: 0x9e08b295, L:/192.168.50.40:52113 - R:/192.168.50.63:63444] FLUSH

抓个WebSocket握手的给你们看看

2018-09-06 17:24:37.050 [nioEventLoopGroup-4-6] INFO NettyServerHandler.java:48 - 发现客户端链接,channel=[id: 0xdb3f7da1, L:/192.168.50.40:52113 - R:/192.168.50.40:56684]
2018-09-06 17:24:37.050 [nioEventLoopGroup-4-6] DEBUG LoggingHandler.java:239 - [id: 0xdb3f7da1, L:/192.168.50.40:52113 - R:/192.168.50.40:56684] READ: 494B
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 73 6c 67 20 48 54 54 50 2f 31 2e |GET /slg HTTP/1.|
|00000010| 31 0d 0a 48 6f 73 74 3a 20 31 39 32 2e 31 36 38 |1..Host: 192.168|
|00000020| 2e 35 30 2e 34 30 3a 35 32 31 31 33 0d 0a 43 6f |.50.40:52113..Co|
|00000030| 6e 6e 65 63 74 69 6f 6e 3a 20 55 70 67 72 61 64 |nnection: Upgrad|
|00000040| 65 0d 0a 50 72 61 67 6d 61 3a 20 6e 6f 2d 63 61 |e..Pragma: no-ca|
|00000050| 63 68 65 0d 0a 43 61 63 68 65 2d 43 6f 6e 74 72 |che..Cache-Contr|
|00000060| 6f 6c 3a 20 6e 6f 2d 63 61 63 68 65 0d 0a 55 70 |ol: no-cache..Up|
|00000070| 67 72 61 64 65 3a 20 77 65 62 73 6f 63 6b 65 74 |grade: websocket|
|00000080| 0d 0a 4f 72 69 67 69 6e 3a 20 68 74 74 70 3a 2f |..Origin: http:/|
|00000090| 2f 31 39 32 2e 31 36 38 2e 35 31 2e 32 33 34 0d |/192.168.51.234.|
|000000a0| 0a 53 65 63 2d 57 65 62 53 6f 63 6b 65 74 2d 56 |.Sec-WebSocket-V|
|000000b0| 65 72 73 69 6f 6e 3a 20 31 33 0d 0a 55 73 65 72 |ersion: 13..User|
|000000c0| 2d 41 67 65 6e 74 3a 20 4d 6f 7a 69 6c 6c 61 2f |-Agent: Mozilla/|
|000000d0| 35 2e 30 20 28 57 69 6e 64 6f 77 73 20 4e 54 20 |5.0 (Windows NT |
|000000e0| 31 30 2e 30 3b 20 57 4f 57 36 34 29 20 41 70 70 |10.0; WOW64) App|
|000000f0| 6c 65 57 65 62 4b 69 74 2f 35 33 37 2e 33 36 20 |leWebKit/537.36 |
|00000100| 28 4b 48 54 4d 4c 2c 20 6c 69 6b 65 20 47 65 63 |(KHTML, like Gec|
|00000110| 6b 6f 29 20 43 68 72 6f 6d 65 2f 36 35 2e 30 2e |ko) Chrome/65.0.|
|00000120| 33 33 32 35 2e 31 38 31 20 53 61 66 61 72 69 2f |3325.181 Safari/|
|00000130| 35 33 37 2e 33 36 0d 0a 41 63 63 65 70 74 2d 45 |537.36..Accept-E|
|00000140| 6e 63 6f 64 69 6e 67 3a 20 67 7a 69 70 2c 20 64 |ncoding: gzip, d|
|00000150| 65 66 6c 61 74 65 0d 0a 41 63 63 65 70 74 2d 4c |eflate..Accept-L|
|00000160| 61 6e 67 75 61 67 65 3a 20 7a 68 2d 43 4e 2c 7a |anguage: zh-CN,z|
|00000170| 68 3b 71 3d 30 2e 39 0d 0a 53 65 63 2d 57 65 62 |h;q=0.9..Sec-Web|
|00000180| 53 6f 63 6b 65 74 2d 4b 65 79 3a 20 55 6c 59 6e |Socket-Key: UlYn|
|00000190| 41 52 63 31 71 45 63 57 51 79 45 54 4d 6a 58 53 |ARc1qEcWQyETMjXS|
|000001a0| 4b 41 3d 3d 0d 0a 53 65 63 2d 57 65 62 53 6f 63 |KA==..Sec-WebSoc|
|000001b0| 6b 65 74 2d 45 78 74 65 6e 73 69 6f 6e 73 3a 20 |ket-Extensions: |
|000001c0| 70 65 72 6d 65 73 73 61 67 65 2d 64 65 66 6c 61 |permessage-defla|
|000001d0| 74 65 3b 20 63 6c 69 65 6e 74 5f 6d 61 78 5f 77 |te; client_max_w|
|000001e0| 69 6e 64 6f 77 5f 62 69 74 73 0d 0a 0d 0a       |indow_bits....  |
+--------+-------------------------------------------------+----------------+
2018-09-06 17:24:37.050 [nioEventLoopGroup-4-6] DEBUG WebsocketInitializeHandler.java:49 - WebSocket链接...
2018-09-06 17:24:37.050 [nioEventLoopGroup-4-6] INFO GameServerNetworkListener.java:47 - 发送初始化封包. id=db3f7da1, encrypt=true, secretkey=2b0557f4-fbd1-4fa3-8f62-b49178576b0e
2018-09-06 17:24:37.051 [nioEventLoopGroup-4-6] DEBUG WebSocketServerHandshaker.java:165 - [id: 0xdb3f7da1, L:/192.168.50.40:52113 - R:/192.168.50.40:56684] WebSocket version V13 server handshake
2018-09-06 17:24:37.051 [nioEventLoopGroup-4-6] DEBUG WebSocketServerHandshaker13.java:136 - WebSocket version 13 server handshake key: UlYnARc1qEcWQyETMjXSKA==, response: kCOFSkzKgXmf1PBOrcGG3FIePVU=
2018-09-06 17:24:37.051 [nioEventLoopGroup-4-6] DEBUG LoggingHandler.java:247 - [id: 0xdb3f7da1, L:/192.168.50.40:52113 - R:/192.168.50.40:56684] WRITE: 129B
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 48 54 54 50 2f 31 2e 31 20 31 30 31 20 53 77 69 |HTTP/1.1 101 Swi|
|00000010| 74 63 68 69 6e 67 20 50 72 6f 74 6f 63 6f 6c 73 |tching Protocols|
|00000020| 0d 0a 75 70 67 72 61 64 65 3a 20 77 65 62 73 6f |..upgrade: webso|
|00000030| 63 6b 65 74 0d 0a 63 6f 6e 6e 65 63 74 69 6f 6e |cket..connection|
|00000040| 3a 20 75 70 67 72 61 64 65 0d 0a 73 65 63 2d 77 |: upgrade..sec-w|
|00000050| 65 62 73 6f 63 6b 65 74 2d 61 63 63 65 70 74 3a |ebsocket-accept:|
|00000060| 20 6b 43 4f 46 53 6b 7a 4b 67 58 6d 66 31 50 42 | kCOFSkzKgXmf1PB|
|00000070| 4f 72 63 47 47 33 46 49 65 50 56 55 3d 0d 0a 0d |OrcGG3FIePVU=...|
|00000080| 0a                                              |.               |
+--------+-------------------------------------------------+----------------+
2018-09-06 17:24:37.051 [nioEventLoopGroup-4-6] DEBUG LoggingHandler.java:263 - [id: 0xdb3f7da1, L:/192.168.50.40:52113 - R:/192.168.50.40:56684] FLUSH
2018-09-06 17:24:37.052 [nioEventLoopGroup-4-6] DEBUG LoggingHandler.java:231 - [id: 0xdb3f7da1, L:/192.168.50.40:52113 - R:/192.168.50.40:56684] READ COMPLETE
2018-09-06 17:24:37.054 [nioEventLoopGroup-4-6] DEBUG LoggingHandler.java:239 - [id: 0xdb3f7da1, L:/192.168.50.40:52113 - R:/192.168.50.40:56684] READ: 52B
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 82 ae 5e 7c 77 77 5e 7c 7a fc 55 7c 7f 75 4c 58 |..^|ww^|z.U|.uLX|
|00000010| 46 13 6c 44 11 4e 6a 4b 5a 15 66 4d 14 5a 6a 4b |F.lD.NjKZ.fM.ZjK|
|00000020| 40 42 73 44 16 41 69 51 4f 42 3d 1e 4e 11 3b 45 |@BsD.AiQOB=.N.;E|
|00000030| 4f 11 6c 4c                                     |O.lL            |
+--------+-------------------------------------------------+----------------+
2018-09-06 17:24:37.054 [nioEventLoopGroup-4-6] DEBUG WebSocket08FrameDecoder.java:174 - Decoding WebSocket Frame opCode=2
2018-09-06 17:24:37.054 [nioEventLoopGroup-4-6] DEBUG WebSocket08FrameDecoder.java:282 - Decoding WebSocket Frame length=46

这个输出是不是跟WPE的界面长得一样一样的…

转载请注明原地址: http://blog.noark.xyz/article/2018/6/2/noark入门之网络封包日志输出/