Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to debug TCP protocol in IM system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to debug TCP protocol in IM system". In daily operation, I believe many people have doubts about how to debug TCP protocol in IM system. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to debug TCP protocol in IM system". Next, please follow the editor to study!

Recently, he is responsible for the development of Guazi IM system. The client uses Wechat's open source Mars library. Define the communication protocol as shown in the following figure.

20-byte header, including headLength header length, clientVersion client version, cmdId command Id number, seq message sequence number, bodyLength message body length; message content body length is identified by bodyLength in header.

After the prototype of the server (named pigeon-gate) and the client (Mars) program is developed, the protocol needs to be jointly debugged. How to determine whether the behavior of sending and receiving messages in Mars is in line with expectations (the expectation is analyzed by reading the Mars source code)? Grab the TCP message package!

Tool wireshark, installed on the machine where the IM server pigeon-gate is located, installed in its own Baidu.

Open the wireshark tool and enter "tcp and ip.addr = = 192.168.13.1" in the filter (the IP is the mobile phone IP address), indicating that only TCP data from the 192.168.13.1 IP address is displayed.

The IM client sends a message, and the tool crawls several TCP packets, where the data marked in the red box is the message data sent by the client to the server (try a few more times to know which one is valid).

Click data to see the contents of the TCP message package as shown in the following figure.

The content of the blue background (cursor) is the content sent from the client to the server (including header,body).

The content with a non-blue background can be simply understood as the header of the TCP protocol (our custom data can be counted as the message body of the TCP protocol).

For example, the 6-byte red box indicates the physical address of the destination (IM server), the physical address of the test server is 68-07-15-29 FEMAE 3B, and the purple box indicates the physical address of the message source (mobile phone). For more information, please see TCP protocol details.

Focus on the blue background area. The first 4 bytes of the message is the header length headLength.

HeadLength,4 bytes, TCP package content is "00 00 00 14", convert hexadecimal to decimal to 20. Follow this method to get

HeadLength = 20

ClientVersion = 200

CmdId = 3

Seq = 2

BodyLength = 36

Based on the received message header, it is judged that the message of the Mars response is as expected. The protocol for the client to send the message to the server is correct, and the server handles it. The protocol joint call through which the client sends the message to the server.

The message body is displayed in clear text, and you can see several phonetic letters of chupengyu.

At this point, the study on "how to debug TCP protocol in IM system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report