当前位置:网站首页>A beginner's entry is enough: develop mobile IM from zero
A beginner's entry is enough: develop mobile IM from zero
2022-06-26 05:05:00 【JackJiang-】
One 、 Preface
IM Up to now , It is one of the most important forms of Internet application , Especially in the mobile Internet era , It is reducing the cost of communication and the cost of communication , It has a profound impact on various application forms .
As IM Developers may soon become IM The developer's technicians ,IM The value and importance of . But in terms of technical implementation ,IM System development ( Especially the mobile end IM) There are still many technical difficulties and pits . And that's why , Quality IM Develop relevant materials 、 Practical achievements , For novices who don't have much technical reserves , Especially difficult to obtain .
This article will guide you to read relevant articles from a novice's perspective , In order to develop a mobile terminal from zero IM Be prepared for all aspects of knowledge : Including but not limited to the basics of network programming 、 Selection of communication protocol 、IM And so on . Writing co., LTD. , If there is something wrong, please criticize and correct it , I hope it works for you .( This article is published synchronously in :http://www.52im.net/thread-464-1-1.html)
Instant messaging development communication : 215891622 [ recommend ]
Two 、 After reading this article
2.1 You will get
This article will assume that you are a novice with no technical preparation , Guide you through a selection of articles , Learn how to start developing a mobile terminal from scratch IM The various technologies required 、 Materials and practical codes .
2.2 You cannot get
Whereas IM The complexity of Technology ,IM Development related technologies can not be demonstrated in an article , For space reasons, this article will not contain any practical code 、 Also try not to make an in-depth development of a certain technology , Relevant practical code 、 Information 、 Please read and learn in depth one by one according to the articles prepared by the author of this article , And this is exactly the purpose of this article .
3、 ... and 、 Digression
In the last two years IM The development of cloud services , Many teams, for a variety of reasons , Directly selected the short, smooth and fast cloud IM Access APP in . However , Considering the cloud IM Whether in terms of business model or operation model , After years of sedimentation , Only then can we truly realize the win-win situation of the virtuous circle of operation and service between customers and service providers . Cause rule , How to select cloud IM Service provider , This is a headache , However, this is not the focus of this article , if necessary , You can also join the discussion group mentioned in this article , Communicate with everyone : 215891622.
Okay , Here's the main content .
Four 、 Network programming theory preparation
4.1 UDP、TCP The theory of agreement
We all know ,IM The business essence of the system is the real-time transmission of messages between the client and the client , The technical foundation is based on Socket Connected real-time data read / write , So the basic network programming theory is the knowledge that you must master as a novice . Of course , As IM development , Basic network theory is enough , There is no need to be as proficient as a network engineer OSI Seven layer reference model .
If you don't know what is UDP、TCP agreement , Please read the following article :
- 《TCP/IP Detailed explanation - The first 11 Chapter ·UDP: User datagram protocol 》
- 《TCP/IP Detailed explanation - The first 17 Chapter ·TCP: Transmission control protocol 》
- 《TCP/IP Detailed explanation - The first 18 Chapter ·TCP Connection establishment and termination 》
- 《TCP/IP Detailed explanation - The first 21 Chapter ·TCP Over time and retransmission 》.
These articles are helpful to UDP、TCP The Agreement establishes a basic understanding , Of course, if time permits , Be able to read the classics of network programming theory 《TCP/IP Detailed explanation volume 1: agreement 》 It can't be better . in addition ,UDP、TCP As the basic computer data transmission protocol , Many application layer protocols have been derived from it , Relevant protocol family diagrams can be found in this article :《 Computer network communication protocol diagram ( Chinese Collection Edition )》, It can be used as your daily reference manual .
4.2 In depth understanding of TCP Transfer protocol
Have a thorough understanding of TCP The connection and disconnection process of the transport protocol is very helpful for you in the future IM Algorithm optimization and implementation , This process is vividly summarized as “3 Shake hands with 4 Second wave ”.
The following article will help you understand :
- 《 Theoretical Classics :TCP Agreed 3 Shake hands with 4 Detailed explanation of the wave process 》
- 《 Combining theory with practice :Wireshark Caught analysis TCP 3 The second handshake 、4 The wave process 》.
4.3 In depth understanding of UDP Transfer protocol
comparison TCP agreement ,UDP The data transmission protocol is very lightweight and easy to understand ,UDP It is usually used in data transmission scenarios that require rapid response , Corresponding to IM The application forms of :P2P signal communication 、 Real time audio and video, etc . in addition , Usual IM Will be used on the Internet ( Not LAN ), So understand the so-called NAT Principles of routing technology, etc , It will also help you to P2P Hole digging 、UDP There is a clear understanding of the concept of port aging .
The following article will help you develop IM It provides some practical basis for the practical application of :
- 《UDP What is the maximum size of a package in ?》
- 《NAT Detailed explanation : The basic principle 、 Crossing technology (P2P Hole digging )、 Port aging, etc 》.
Of course , Current network programming , To solve the problem of high performance , There are many shaped Socket The application layer pattern exists , such as :NIO、AIO etc. , article 《Java New generation network programming model AIO Principle and Linux System AIO Introduce 》 This paper briefly introduces the traditional blocking mode IO、NIO, The latest AIO technology , If you have time, it is necessary for you to know .( More articles of the same kind : Click here to enter …)
5、 ... and 、 Basic practice of network programming
If you have read the articles on the previous level carefully , It's time to write some code , To integrate theory with practice Socket The principle and practice of communication .
of TCP Of Socket signal communication Demo Articles and code :
- 《Android The client and server are based on TCP Agreed Socket Communications 》
- iOS Platform CocoaAsyncSocket There are many in managed code TCP The official Demo Code , It's worth seeing. .
Of course , So I was just looking for it Demo Code , On the Internet TCP Demonstrative code for data communication is easy to find , There are no more examples here .
The author of this article has specially written the cross mobile platform UDP Socket signal communication Demo:
- 《NIO Introduction to framework ( One ): Server based on Netty4 Of UDP Two-way communication Demo demonstration 》
- 《NIO Introduction to framework ( Two ): Server based on MINA2 Of UDP Two-way communication Demo demonstration 》
- 《NIO Introduction to framework ( 3、 ... and ):iOS And MINA2、Netty4 cross-platform UDP Two way communication practice 》
- 《NIO Introduction to framework ( Four ):Android And MINA2、Netty4 cross-platform UDP Two way communication practice 》.
6、 ... and 、IM It should be used in the end UDP still TCP agreement ?
Okay , After mastering the above network programming foundation , It's time to start working for your IM Select the transmission protocol . Speaking of IM This use UDP still TCP As a transport protocol , This is a controversial topic , Every time this problem occurs in major communities, it must be a large number of different voices .
Of course ,UDP and TCP Each has its own application scenario , As IM Come on , In the early IM Because the server-side resources ( Server hardware 、 Network bandwidth, etc ) It is expensive and there is no better way to share the performance load , So many times I will consider using UDP, This is mainly early QQ As a representative .
today ,TCP The server-side load of has a good solution , In addition, the cost of server resources has decreased , At present a lot of IM、 Message push solutions are also being used TCP As a transport layer protocol . however ,UDP Nor is it excluded from IM、 Message push solutions , such as : Weak network communication ( Including transnational high latency network environment )、 Internet of things communications 、IM In real-time audio and video communication, etc ,UDP Still a preference .
The following article may help you to choose the transport layer protocol :
- 《 Why? QQ It's using UDP Agreement, not TCP agreement ?》
- 《 Mobile instant messaging protocol selection :UDP still TCP?》
- 《 Technical test and analysis of the influence of wechat on the network ( Paper full text )》
- 《 Why based on TCP The mobile end of the protocol IM We still need a heartbeat mechanism ?》.
Of course , About IM It's time to choose UDP still TCP, It's a matter of different opinions , There is no need to be too tangled , Please start from your IM Overall application scenario 、 Development costs 、 Comprehensive consideration of deployment and operation costs , I believe I can find the answer you want .
7、 ... and 、IM Data communication format selection based on
IM In the early stage of application and development, when selecting the technology , Selection of data communication format , In the eyes of peers , Yes, it is also a very controversial topic .
Analyze carefully , The reason is , Probably lies in the following points :
- There are a variety of protocols or encapsulation formats to choose from :
There is a wide range of options :XMPP、Protobuf、JSON、 private 2 Base number 、MQTT、 Freeze frame XML、Plain text wait ; - The same format is not applicable to most scenarios :
Different scenarios have the same considerations, and the choice of protocol is often linked to this , Such as : Mobile IM Or push XMPP When the agreement , In most cases, it will be sprayed ; - Developers have their own preferences for the selected format :
Some people or teams have different experience and technical accumulation in one or several formats , It also contributes to their preference for one or more agreements .
What data communication format should be selected , It is also related to your application scenario and architecture scheme . however , At present, according to the information available to the author , As a device that needs to run on a mobile device IM, It is not recommended in almost all current mainstream discussions XMPP agreement , The specific reasons are not here , The following recommended articles will explain the reasons in detail .
The following article will be helpful to your IM Data communication format selection is helpful :
- 《 How to choose the data transmission format of instant messaging application 》
- 《 The strong proposal will Protobuf As your IM application data transfer format 》
- 《 Mobile IM The technical problems that development needs to face ( Including communication protocol options )》
- 《 Brief introduction of mobile terminal IM The pits developed : Architecture design 、 Communication protocol and client 》
- 《 Combining theory with practice : A typical set of IM Communication protocol design details 》
- 《58 Home real-time message system protocol design and other technical practice sharing 》
- 《 Literacy stickers : know MQTT Communication protocol 》.
( More articles of the same kind : Click here to view the …)
8、 ... and 、 Mobile IM Keep your heartbeat alive and push background messages
8.1 Why do I need to keep my heart beating ?
Due to the complexity of mobile networks , The heartbeat is kept alive for the mobile terminal IM It's especially important , In addition, the mobile phone saves electricity 、 Design of traffic saving strategy , How to keep the heartbeat alive is also very important , article 《 be based on TCP The mobile end of the protocol IM We still need a heartbeat mechanism 》 Maybe it can answer your question .
8.2 iOS Background message push on the client
because iOS The particularity of the platform ,iOS Once the app goes back to the background , The application itself can't use code to keep the network alive , You can't push the background messages by yourself .
The following article will help you understand iOS The background message push principle of the platform :
- 《iOS The push service of APNs Detailed explanation : Design thinking 、 Technical principles and defects, etc 》
- 《 Literacy stickers : Talking about iOS and Android The principle and difference of background real-time message push 》.
8.3 Android The heartbeat of the client is kept alive and the background message is pushed
Whereas Android The differentiation and incompatibility of the platforms are well known ,Android End IM When processing heartbeat preservation and background message push , Encountered a lot of trouble . and , because Android Application lifecycle management is controlled by the system , So how to ensure your IM The process or background service is not killed by the system , It is the basis for realizing heartbeat keeping alive and background message pushing .
The following article is for your Android End IM It provides a reference for the design of heartbeat keeping alive and background push scheme :
- 《Android Detailed explanation of process assurance : One article solves all your questions 》
- 《Android End message push summary : Realization principle 、 The heartbeat keeps alive 、 Problems encountered, etc 》
- 《 Why based on TCP The mobile end of the protocol IM We still need a heartbeat mechanism ?》
- 《 Wechat team original sharing :Android Version of wechat backstage to keep the real battle sharing ( Keep the process alive )》
- 《 Wechat team original sharing :Android Version of wechat backstage to keep the real battle sharing ( Network security chapter )》
- 《 Mobile IM practice : Realization Android Version of wechat's intelligent heartbeat mechanism 》
- 《 Mobile IM practice :WhatsApp、Line、 Heartbeat strategy analysis of wechat 》
( More articles of the same kind : This entry …)
Nine 、 Mobile IM Architecture design of the system
IM Its essence is a set of message sending and delivery system , Or a network communication system , It comes down to two words : Store and forward . But a mature mobile terminal IM If the system is to work properly , The content involved is far more than that , The most challenging technical skill is the design and implementation of the server architecture .
Never IM People with experience in system development , May scoff at the above view , Here I borrow TeamTalk A passage from the designer of :“IM Server development , From the perspective of functional abstraction, it can be very simple , It can be thought of as managing a large number of client connections and passing messages between different clients , But the implementation details are more complicated . Make an inappropriate metaphor ,OS The functional abstraction of is also very simple , It is nothing more than inter process scheduling and hardware resource management , But if you want to achieve one , Ordinary people can only ha ha .”
Let's take a typical scheme as an example , First, let's refine one IM The main requirements of the system : Including account number 、 Relational chain 、 Online status display 、 Message interaction ( Text 、 picture 、 voice )、 Real time video phone .......
Deal with the above requirements , We usually need to consider the following aspects to design a suitable architecture :
- If a reliable transmission protocol is used TCP, Load issues need to be considered : The short connection realizes the account number 、 Relationship chain related business , Long connection to realize online 、 Information push ;
- Flexibility of the background architecture 、 Extensibility : Support distributed deployment —— Put the network layer 、 Business logic layer 、 Data layer separation , The network layer and the service layer support load balancing strategies 、 The data layer supports distributed storage ;
- client SDK Ease of use : Put the network layer 、 Data layer separation 、 Separation of business logic layer .
in addition , A typical IM System architecture design , There are also the following hot performance issues that need designers' attention :
- Coding angle : Adopt an efficient network model , Threading model ,I/O Processing model , Reasonable database design and optimization of operation statements ;
- Vertical expansion : Improve the performance by increasing the hardware resources or network resources of a single server ;
- Horizontal expansion : The load is shared through reasonable architecture design and load balancing strategy in operation and maintenance , Improve performance ; You can even consider adding a data cache layer later , breakthrough IO bottleneck ;
- High availability of the system : Prevent a single point of failure ;
- In the architecture design, the business processing and data are separated , Thus, depending on the distributed deployment, the system availability can be guaranteed in case of single point of failure .
- For key independent nodes, dual machine hot standby technology can be used for switching .
- The security of database data can be solved through the redundant configuration of disk array and the primary and standby databases .
Given the limited space , The content of architecture design will not be expanded in this paper .
The following article will be for your mobile terminal IM The architecture design of the system brings certain reference significance :
- 《 Talking about IM Architecture design of the system 》
- 《 Brief introduction of mobile terminal IM The pits developed : Architecture design 、 Communication protocol and client 》
- 《 A set of original distributed instant messaging (IM) System theoretical framework scheme 》
- 《 From zero to excellence : The evolution process of the technical framework of JD customer service instant messaging system 》
- 《 Mushroom Street im /IM Architecture selection of server development 》
- 《 tencent QQ1.4 Technology challenges and architecture evolution of 100 million online users PPT》
- 《 Wechat technical director talks about architecture : The way of WeChat —— The greatest truths are the simplest ( Speech full text )》
- 《 How to interpret 《 Wechat technical director talks about architecture : The way of WeChat —— The greatest truths are the simplest 》》
- 《 Fast fission : Witness the powerful background architecture of wechat 0 To 1 The evolution of ( One )》
- 《17 Year's practice : Technical methodology of Tencent's massive products 》.
( More articles of the same kind : Click here to enter …)
Ten 、 Mobile IM Communication security
IM( Especially mobile terminal IM) Security has always been a basic issue that developers need to give priority to , How to correctly understand and use encryption technology is particularly important .IM Most systems use C/S、B/S、P2P And other technologies to realize the function of instant messaging , There is no unified standard for software programming , bring IM There are many security vulnerabilities in the system itself , Coupled with the lack of security awareness of users , It leads to various security problems when using instant messaging system .
The main functions of computer cryptography today are : encryption ( Encryption)、 authentication (Authentication), Identification of (Identification) .
encryption : Prevent bad people from accessing your data .
authentication : Prevent bad people from modifying your data and you don't find it .
authentication : Prevent bad people from passing off your identity .
These basic concepts and encryption algorithm principles are not described here .
The following article may help you design a secure mobile terminal IM System :
- 《 Instant messaging security ( One ): Understand and use... Correctly Android End encryption algorithm 》
- 《 Instant messaging security ( Two ): The combination encryption algorithm is discussed in IM Application in 》
- 《 Instant messaging security ( 3、 ... and ): Commonly used encryption and decryption algorithm and communication security 》
- 《 Instant messaging security ( Four ): The example analysis Android The risk of hard key coding in 》
- 《 Transport layer security protocol SSL/TLS Of Java Platform implementation and Demo demonstration 》
- 《 Combining theory with practice : A typical set of IM Communication protocol design details ( Including security layer design )》
- 《 Wechat new generation communication security solution : be based on TLS1.3 Of MMTLS Detailed explanation 》
- 《 From Ali OpenIM: Create a safe and reliable instant messaging service technology practice sharing 》.
( More articles of the same kind : Click here to enter …)
11、 ... and 、 of IM Real time audio and video technology in
IM Real time audio and video technology in application , Almost IM The last high wall in development . The reason lies in : Real time audio and video technology = Audio and video processing technology + Network transmission technology Horizontal technology application aggregation of , And the public Internet is not designed for real-time communication . The implementation of real-time audio and video technology mainly includes : Collection of audio and video 、 code 、 Network transmission 、 decode 、 Play and other links . So many technology applications are not simple , If not , Will encounter one pit after another in the actual development process .
The following article will help you understand IM All aspects of real-time audio and video development :
- 《 Audio and video development of instant messaging ( One ): The theory of video codec 》
- 《 Audio and video development of instant messaging ( Two ): Digital video introduction of video coding and decoding 》
- 《 Audio and video development of instant messaging ( 3、 ... and ): Coding basis of video coding and decoding 》
- 《 Audio and video development of instant messaging ( Four ): Prediction technology of video codec 》
- 《 Audio and video development of instant messaging ( 5、 ... and ): Understanding the mainstream video coding technology H.264》
- 《 Audio and video development of instant messaging ( 6、 ... and ): How to start learning audio codec technology 》
- 《 Audio and video development of instant messaging ( 7、 ... and ): Introduction to audio fundamentals and coding principles 》
- 《 Audio and video development of instant messaging ( 8、 ... and ): Common real-time voice communication coding standards 》
- 《 Audio and video development of instant messaging ( Nine ): Echo and echo cancellation of real-time voice communication summary 》
- 《 Audio and video development of instant messaging ( Ten ): Echo cancellation in real-time voice communication Technical details 》
- 《 Audio and video development of instant messaging ( 11、 ... and ): Detailed explanation of packet loss compensation technology in real-time voice communication 》
- 《 Audio and video development of instant messaging ( Twelve ): Discussion on the framework of real-time audio and video chat for multiple people 》
- 《 Audio and video development of instant messaging ( 13、 ... and ): Real time video coding H.264 Characteristics and advantages of 》
- 《 Audio and video development of instant messaging ( fourteen ): Real time audio and video data transmission protocol 》
- 《 Audio and video development of instant messaging ( 15、 ... and ): Chat P2P And real-time audio and video applications 》
- 《 Audio and video development of instant messaging ( sixteen ): Some suggestions on the development of real-time audio and video in mobile terminal 》
- 《 Audio and video development of instant messaging ( seventeen ): Video coding H.264、V8 The past and this life 》
- 《 Open source real-time audio and video technology WebRTC Advantages and disadvantages 》
- 《 Conscience sharing :WebRTC Zero basic developer tutorial ( chinese )》.
( More articles of the same kind : Click here to enter …)
Twelve 、 Mobile IM Other hot issues of development
Mobile IM During the development, we will also encounter contents not mentioned above , The following article may be useful for you :
《 Mobile IM The technical problems that development needs to face 》
《 Development IM Is it better to use byte stream or character stream to design your own protocol ?》
《 Do you know the mainstream way of voice message chat ?》
《IM How to ensure the reliable delivery of messages in the system ( namely QoS Mechanism )》
《 Talk about mobile IM Optimization of login request in development 》
《 It's completely self-developed IM How to design “ Failure to retry ” Mechanism ?》
《 Technical test and analysis of the influence of wechat on the network ( Paper full text )》
《 The principle of instant messaging system 、 Technology and Application ( Technical papers )》
《 Open source IM engineering “ Mushroom street TeamTalk” The status quo of : An open source show with no end 》
>> More articles of the same kind ……
appendix : Other IM articles
[1] of WEB End instant messaging development :
《 Novice entry post : In the history of the most complete Web Detailed explanation of the principle of end instant messaging technology 》
《Web End instant messaging technology inventory : Short polling 、Comet、Websocket、SSE》
《SSE Technical details : A brand new HTML5 Server push event technology 》
《Comet Technical details : be based on HTTP Long connection Web End real-time communication technology 》
《WebSocket Detailed explanation ( One ): A preliminary understanding WebSocket technology 》
《socket.io A little practice and thinking of message push 》
>> More articles of the same kind ……
[2] Articles on Push Technology :
《iOS The push service of APNs Detailed explanation : Design thinking 、 Technical principles and defects, etc 》
《Android End message push summary : Realization principle 、 The heartbeat keeps alive 、 Problems encountered, etc 》
《 Literacy stickers : know MQTT Communication protocol 》
《 One is based on MQTT Integrity of communication protocol Android push Demo》
《 Ask for advice android Message push :GCM、XMPP、MQTT The advantages and disadvantages of the three schemes 》
《 Mobile real-time message push technology analysis 》
《 Literacy stickers : Talking about iOS and Android The principle and difference of background real-time message push 》
《 Absolutely dry : be based on Netty Push service technology points to achieve massive access 》
《 Mobile IM practice : Google News push service (GCM) Research ( From wechat )》
《 Why wechat 、QQ In this way IM Tools not used GCM Service push message ?》
>> More articles of the same kind ……
[3] More instant messaging technology good article classification :
http://www.52im.net/forum.php?mod=collection&op=all
( This article is published synchronously in :http://www.52im.net/thread-464-1-1.html)
author :Jack Jiang ( Click the author name to enter Github)
Source :http://www.52im.net/space-uid-1.html
communication : Welcome to the instant messaging development exchange group 215891622
Discuss :http://www.52im.net/
Jack Jiang At the same time 【 original Java Swing Appearance engineering BeautyEye】 and 【 Lightweight mobile instant messaging framework MobileIMSDK】 The author of , You can go to download and exchange .
边栏推荐
- Dbeaver installation and configuration of offline driver
- Sentimentin tensorflow_ analysis_ layer
- Transport layer TCP protocol and UDP protocol
- 86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)
- Multipass中文文档-与实例共享数据
- C# 39. string类型和byte[]类型相互转换(实测)
- pycharm 导包错误没有警告
- Multipass Chinese document - remote use of multipass
- ThreadPoolExecutor实现文件上传批量插入数据
- Numpy data input / output
猜你喜欢
【Latex】错误类型总结(持更)
UWB ultra high precision positioning system architecture
ROS 笔记(07)— 客户端 Client 和服务端 Server 的实现
LeetCode 19. Delete the penultimate node of the linked list
广和通联合安提国际为基于英伟达 Jetson Xavier NX的AI边缘计算平台带来5G R16强大性能
天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
2022.1.24
Zuul 實現動態路由
5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
Image translation /gan:unsupervised image-to-image translation with self attention networks
随机推荐
-Discrete Mathematics - Analysis of final exercises
Comment enregistrer une image dans une applet Wechat
Multipass Chinese document - remote use of multipass
两步处理字符串正则匹配得到JSON列表
Codeforces Round #802 (Div. 2)(A-D)
天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
Interpretation of yolov5 training results
Numpy random number
ModuleNotFoundError: No module named ‘numpy‘
Ai+ remote sensing: releasing the value of each pixel
Some parameter settings and feature graph visualization of yolov5-6.0
tensorlow:cifar100_ train
Multipass Chinese documents - improve mount performance
一个从坟墓里爬出的公司
LSTM in tensorflow_ Layers actual combat
Condition query
【Unity3D】刚体组件Rigidbody
Dbeaver installation and configuration of offline driver
Learn from small samples and run to the sea of stars
MySql如何删除所有多余的重复数据