im-Instant Messaging Technology Overview

Source: Internet
Author: User
Tags xml parser

im-Instant Messaging Technology OverviewBrief Introduction

Instant Messaging Technology (IM) enables users to chat online in real time. If you want to send a message, the user needs to open a small window to let the user and his friends enter the information and have both parties see what they are talking about. Most commonly used instant Messaging senders offer a variety of features

    1. Instant Messaging-send messages back and forth between users and online friends
    2. Chat-Create a custom chat room for users with friends or coworkers
    3. Web links-Share your favorite URLs
    4. Support Pictures-Browse pictures from your friends ' computers
    5. Support sound-play music for friends
    6. Support file transfer-send files directly to friends for easy sharing
    7. talk-Use the Internet instead of the phone to have a real conversation with friends
    8. Video streaming Content-real-time or quasi-real-time stock quotes or news


there are many IM systems, such as AOL IM, Yahoo im, and MSN IM, which use different technologies and are incompatible. In order to create a unified standard for instant messaging, people have tried several times: the initial protocol of the IETF's Conversation Initiation Protocol (SIP) and Instant Messaging dialog and the Presentation Extension Protocol (simple), the Application Switching Protocol (APEX), the display and Instant Messaging Protocol (PRIM), and the XML-based and open extensible Communication and Presentation Protocol (XMPP) protocol (often referred to as the Jabber protocol). There have been many attempts to unify the standards of major IM vendors (AOL, Yahoo, and Microsoft), but none have been successful and every IM continues to use the protocols it owns.
Common Instant Messaging protocolsXMPP

Extensible Communication and Presentation Protocol (XMPP): XML elements for streaming quasi-real-time communications, representations, and request-response services. XMPP is based on the Jabber protocol and is an open and common protocol for Instant messaging. Although XMPP is not fused by any of the specified network architectures, it is often used in client/server architectures where the client needs to use the XMPP protocol to access the server through a TCP connection, and the server is connected to each other through a TCP connection.

Simple

Instant Messaging Dialog Initial protocol and Presentation Extension Protocol (SIMPLE): The simple protocol specifies a full set of schema and extension specifications for the SIP protocol, and SIP is an Internet telephony protocol that can be used to support IM/message representations. SIP can transmit signals in a variety of ways, such as INVITE signals and BYE signals, respectively, for starting and ending sessions. On this basis, the simple protocol also adds another way of requesting the message signal, which can be used to send a single paging of instant messaging content, that is, the paging mode of instant messaging. The SUBSCRIBE signal is used to request that the display information be sent to the requestor, while the NOTIFY signal is used to transmit the display information. Participants in longer IM conversations need to transmit a variety of latency information, using INVITE and a message session Relay protocol (MSRP). In conjunction with the simple Protocol, the MSRP protocol can be used for text transmission of IM, just as with the SIP protocol, the RTP protocol can be used to transmit voice packets in an IP phone.

Jabber

Jabber:jabber is an open, XML-based protocol for the transmission and presentation of instant Messaging messages. Thousands of servers in the Internet use Jabber protocol-based software. A key concept in the Jabber system is "transmission", also called "Gateway", which allows users to access the network using other protocols such as AIM and ICQ, MSN Messenger and Windows Messenger, SMS or e-mail.

CPIM

Instant Messaging Universal Fabric Protocol (CPIM): CPIM defines the format of common protocols and messages, and both instant messaging and display services are CPIM to achieve collaboration in IM systems.

IRCP

Internet Forwarding Chat Protocol (IRCP): IRCP supports communication between two client computers, one-to-many (all) client computers, and server-to-server communications. This protocol provides a technical basis for most Internet instant messaging and chat systems. The IRC protocol has been developed in the TCP/IP network system, although there is no need to specify that this is the only operating environment for the IRC protocol. The IRC protocol is a text-based protocol that uses the simplest client program as an interface (socket) program for its connection to the server.


XMPP Development related references
    • Official website: http://xmpp.org
    • XMPP client libraries, including JavaScript (STROPHEJS) and C ([1]): http://strophe.im
    • Social Stream's full package: https://github.com/ging/social_stream/wiki/Getting-Started-With-Social-Stream-Presence
    • StackOverflow's Discussion sticker: http://stackoverflow.com/questions/4769020/android-and-xmpp-currently-available-solutions
Android vs. XMPP

Based on the open source XMPP im Protocol, the C/S architecture is designed to connect to the server with the TCP protocol via GPRS wireless network to erect the open source Openfn ' E server as an instant communication platform.

The system is mainly composed of the following parts:

The
first is the server, which is responsible for managing the connection or the session with other entities, receiving or forwarding the XML (extensiblemarkup Language) stream element to the authorized client, the server, etc.
, and the
client terminal. It is connected to the server and obtains all the functionality provided by the server or any other related services through XMPP.
The third is the Protocol gateway. Complete the translation between the information transmitted by the XMPP protocol and the information that the external message system can recognize.
and then the
XMPP network. The connection between each server and client is realized. The system uses the client/server architecture architecture.
Client

The client is developed based on the Android platform. The client is responsible for initiating the creation of a connection request to the server when it initiates the communication process for instant communication. The system connects with Internet network through GPRS wireless network, and realizes instant communication with Android client through the server.

Server-Side

The server side uses OpenFire as the server. Allows multiple clients to log on concurrently and connect to a server concurrently. The server authenticates each client's connection, and the client-to-server communication is performed in the context of that session.


Reference: http://www.ithao123.cn/content-1494500.html

1.1 Server-side design (this piece can almost be said to have finished.) Not much to tangle with)

ANDROIDPN server-side is implemented in the Java language, based on the OpenFire Open source project, the Web Part uses the spring framework, which is different from OpenFire. The ANDROIDPN server consists of two sections, one that listens to the XMPP service on a specific port and is responsible for communicating with the client's Xmppconnection class, which is user registration and authentication, and sends a push notification message. The other part is the Web server, which uses a lightweight HTTP server that is responsible for receiving Web requests from users.

      The main four components are Sessionmanager,auth Manager,presencemanager and notification Manager respectively. SessionManager is responsible for managing the client-server session, Auth Manager is responsible for client user authentication management, and Presence Manager is responsible for managing the client user's login status. The Notificationmanager is responsible for implementing the server push message function to the client.
      The system client is based on the Android phone platform. Use XMPP as an Instant messaging protocol. XMPP is an XML-based communication protocol that realizes quasi-real-time exchange of structured information for any two network terminals. Parse the XML using the XML parsing package provided by the Android platform. Because the app activity is running on the main thread. Therefore, multithreading technology is used to solve the problem of system communication. For communication security issues. The user information and chat information of the system are stored in the SQLite database of the Android platform itself, and the multimedia files and picture files are stored in the SD card of the Android platform virtual file storage device.


       Communication module is responsible for building communication with the server old. Processing is done by creating 3 threads. It is responsible for sending, receiving and transmitting heartbeat information, and parsing module is mainly used to parse the XML data stream. Different types of data objects are encapsulated according to the parsing elements: The data module defines most of the data types and objects throughout the client, and application modules include instant messaging, picture browsing, and music playback. Is the interface between the client and the user, and the encryption module decrypts the messages sent and received. To ensure the security of your communications data.


The client of the system is divided into 5 modules for design and development, 2 shows.


      Communication module is responsible for building communication with the server old. Processing is done by creating 3 threads. It is responsible for sending, receiving and transmitting heartbeat information, and parsing module is mainly used to parse the XML data stream. Different types of data objects are encapsulated according to the parsing elements: The data module defines most of the data types and objects throughout the client, and application modules include instant messaging, picture browsing, and music playback. Is the interface between the client and the user, and the encryption module decrypts the messages sent and received. To ensure the security of your communications data.

Encryption (binary code is converted to BASE64 code first, after conversion to BASE64 code, then MD5 encryption,)

The TCP connection between the XMPP server and between the client and the server is ignored. TCP provides a tile-to-connect, reliable byte-stream service. Maintain a real-time, bidirectional transmission channel. TCP Packages the user data to form a message segment. It sends the data and starts a timer, waits for the peer data to confirm, the other end confirms the received data, re-sorts the unordered data, and discards the duplicate data; TCP provides end-to-end traffic control. Calculate and validate a mandatory end-to-end inspection. However, the GPRS network has a limitation on the TCP link. When the TCP link is not having data traffic for a long time. The priority of this link is automatically lowered until the link is forcibly disconnected. So in the application. This link is maintained by sending a heartbeat.

Data format
       XML is at the heart of the XMPP system architecture. It can represent almost any kind of structured data. In particular, XMPP makes use of XML data streams for client-side, server-side, one-server-side communication. XML data flow is typically initiated by the client to the server, and the effective time of the XML data stream is directly associated with the user's online session validity time.
Protocol Message Format

The XMPP protocol consists of 3 top-level XML elements: Message, Presence, and IQM. The message is used to represent the transmitted messages when the user sends a message. A message element is inserted in the context of the stream with relevant information sent by the user; presence is used to represent the state of the user. When the user changes their state. A presence element is inserted in the context of the data flow to represent the user's current state; IQ is used to represent a request, a response mechanism, a request is sent from one entity, and another entity accepts the request and responds.

Backstage Servic:


From the level of the class to see this structure is relatively simple, let it become complex, it has three threads: the main thread, the XMPP communication thread, connection error retry thread.


Description of the diagram:

1. Create a single thread in Notificationservice to connect to the server, because using XMPP to connect the server is divided into three steps: Connect, register, log in. So use a stack to save the task Tasks (connecttask,registertask,logintask) to be executed, and then execute them in that order.
2. The thread connecting the XMPP server is using Executors.newsinglethreadexecutor (), which itself can not stop the submit task. Why do I have to use a stack to save a task?
4. In Logintask, if the server is logged in, it registers a listener to listen for server push packets (Packet), and then notifies the program to be displayed by sending a broadcast.
5. After landing the server, there may be errors, so after landing, will be set up a connectionlistener, for monitoring the connection error, and then appropriate reconnection process, to re-connect
6. During the landing process, there is a mistake to deal with alone, that is, when the account and password is invalid, this time its return status code is 401, this situation should be the local saved account and password are cleared, and then re-connect, or will never land on the server side.

Since all the functions of the system are based on the communication of the XML stream between the networks, a module is dedicated to the processing of the network and the XML stream, and the main functions include the processing of TCP sockets, the parsing of XML streams, and the storage functions of the server and client.


The data module is responsible for parsing XML stream and encapsulating XML module, the main function is: parse the XML stream into Java object, encapsulate the Iava object into XML stream;

The process is that after the XMPP server receives the XML stream, there will be an accessor to read it out and pass it as an entry parameter into the XML parser, the XML parser through the parsing of its namespace, to determine the remaining XML elements to parse out and pass in the corresponding; Ava object, This eventually translates the XML into an Iava object, then passes the Iava object into the application module, implements its request completion function and returns the Iava object, but the Iava object cannot be transmitted directly in the network and must first be converted to an XML section, and the Iava object is passed into the XML wrapper. is encapsulated into an XML section that is sent to the destination node through the send port of the XMPP server.

The process of processing the Java Object Processing module is as follows: When the module receives the Iava object, it decrypts the object through the decryption algorithm and decryption key into the Base64 code, then the F-ear converts the Base64 code into binary code, thus realizing the parsing of the Java object. When the business logic is processed, the module converts the returned Java object from binary code to Base64 code, and then encrypts it with an encryption algorithm, where the cryptographic algorithm is negotiated by the two parties through three handshake protocols when establishing the session.

When the XML section is encapsulated as a Java object, it must be forwarded to the order: correct module to be processed, which requires a routing forwarding module, 3-3. The module is implemented by loading the routing module at system startup, creating a routing module in memory, recording the correspondence between named NULL and functional modules, and when the Iava object is encapsulated, the system reads its namespace and then finds its corresponding module in the routing table, which dynamically loads the module , and forwards the Java object to the module, which enables the function of road Hill forwarding.

im-Instant Messaging Technology Overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.