| Nowadays,mobile Internet technology is developing rapidly,especially the launch of 5G.The highest theoretical transmission speed can reach tens of Gb per second,which is hundreds of times faster than the transmission of 4G network.The speed of network transmission is no longer the bottleneck of network communication system.With the continuous improvement of network speed,various new products emerge in an endless stream.The devices that can access the Internet are not limited to handheld devices such as mobile phones or tablet computers,but expand to intelligent devices such as cars,air conditioners,speakers,etc.which greatly increases the amount of data in the network.At the same time,the new business scene requires more and more real-time performance and stability of the system,and the user's demand for product experience is getting higher and higher,so developing a stable and fast instant messaging system can greatly improve the user experience,which is of great significance.This paper designs and implements a distributed instant messaging system,which completes the server's dynamic online and offline in about 3 seconds,and supports the server's "elegance" offline.In the choice of communication protocol,communication protocol,such as XMPP,MQTT and so on,after comparison the advantages and disadvantages of each protocol,determined using a custom protocol,the main protocol is Google Protocol Buffer developed by Google,before the main report body,adds self-defined header,for identifying the message length and data encryption and decryption.In the process of cross service message processing,REDIS is used as the intermediate cache,each server to fetch the user's message,and a strategy is designed to avoid invalid polling,resulting in high server load.In connection mode,a long connection based on TCP is used,and a heartbeat mechanism is used to check the connection regularly between the client and the server.Finally,in order to facilitate the testing of the system,the client program is developed,and registration,login,sending messages,modifying passwords,adding friends,deleting friends,creating groups and other business functions are realized. |