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!