IOS Swift Project IM implementation, from long-connect to the underlying data analysis socket
A: Project introduction: Last year began to take over a state-owned enterprise mobile project, the demand for the project is to achieve im Instant messaging capabilities.
* The first edition features include:
1. approval of the company's business, quotation and award approval process;
2. single chat and group chat (lead daily work exchange);
3. Chat messages include support for text-like messages, languages, pictures, and language support across platforms;
4. the network data transmission of the message realizes the encryption compress processing, guarantees the data safe transmission;
* Features of the project:
Because of the project business: approval, quotation and the specificity of the award approval process, IM implementation can not be applied to third parties, such as: Aurora push, etc., so it is necessary to implement processing socket bottom data to solve the planing.
Second: TheiOS IM feature is implemented using the TCP request protocol of the socket, it is recommended to use a third party sdk:cocoaasyncsocket
Cocoaasyncsocket:oc version, is the application of GCD write asynchronous processing, interested can go to see the original code
Pod ' cocoaasyncsocket '//Can be integrated via pod
Four: Cocoaasyncsocket Init and delegate
* Implementation of Cocoaasyncsocket 4 agents to handle socket communication data, the following analysis of the role of each agent:
1.-(void) Socket: (Gcdasyncsocket *) sock didconnecttohost: (NSString *) host port: (uint16_t) port;
2.-(void) Socketdiddisconnect: (Gcdasyncsocket *) sock witherror: (Nullable nserror *) err;
* With success, there must be failure:
The status of the update includes: 1: Network status, 2: User Data Sync status, 3: Heartbeat interval, 4: Forced reconnection
Note: (a robust and well-performing IM system, the factors to consider are important)
Note: This project is always responsible for Wang, is the backstage born, the whole project backstage (report EQ system, ERP system) system has the Wang Total building, backstage of the entire IM framework is also the Wang total integration, maintenance and improvement,
The position of state-owned enterprises is highly and technically comprehensive indeed admired.
3.-(void) Socket: (Gcdasyncsocket *) sock Didwritedatawithtag: (long) tag;
4.-(void) Socket: (Gcdasyncsocket *) sock didreaddata: (NSData *) data withtag: (long) tag;
Instruction message (SYC instruction), heartbeat message, init message, and Invoke (get) message;
V: Socke Summary
* The socket connection layer of the cocoaasyncsocket is almost there, and the regulations listed above are the places that require great attention.
* The IM Connectivity layer also has a very important place: need to monitor the network status of the project, the change of network status needs to be handled,
4G network needs to remind the user, the virtual network needs to optimize the processing of IM tasks, in the case of disconnection reconnection to prioritize network status,
These are performance optimizations for IM systems that provide a resilient foundation for project iterations.
Note: Next: IOS Swift project IM implementation, Payload Data packaging and parsing from long connections to data flow analytic analysis.