I hope you can discuss the design of the instant messaging protocol.

Source: Internet
Author: User

Recently, when I was writing an Instant Messaging Server, I encountered a dilemma about session design in communication protocols.

First, let's talk about some existing protocol designs:

 

1. MSN, sip, fetion (SIP)

In this Protocol, both parties need to establish a session. First, a session creation request is sent. The following uses a sip conversation as an example:

 

First, send an invite to the server, and then receive the OK message to start the dialog. The same is true for the protocol design of MSN. However, MSN will enable a new socket after the invite.

This protocol design makes it easy to design the server architecture. After the server receives the invite, it can establish a session cache when establishing the socketconnection between the two parties to improve performance.

However, this design is very troublesome for the client. Before sending information, the client first needs to check whether a session has been established. If not, it needs to re-establish the session.

 

2. QQ and Gtalk (XMPP) Protocols

This protocol is designed to specify the receiving object in the message of a session, so you do not need to send a request to establish a session. For example, XMPP protocol:

Send: <message to 'sd@jabber.org'>
<Body> where are you? </Body>

</Message>

The client can directly send information as long as the mesasge receiver is specified.

This protocol design will make the client very simple, but the server design will be very troublesome. If you do not cache the session Parties, You need to search the route table for each client message, which consumes a lot; if the cache is designed, the cache timeout and other mechanisms will be complicated.

 

I hope you can help us with some solutions. Thank you!

 

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.