Instant Messaging Software Design (I)

Source: Internet
Author: User
Tags types of extensions

I wrote a talk about the mobile market, and I wanted to write this series later. Including instant messaging and player. Later, because I had to go home and add my friends to watch the house, I had to wait. Today, let's talk about soy sauce at work. I also took this opportunity to scold the property market. All county towns are over four thousand. I am not talking about this nonsense.

To build a software program, you must first make it clear that you are not single-host or distributed, cs or bs. These are post-scripts. The first problem encountered was what functions the software should implement, that is, what the market and developers' expectations for the software are.

Because the instant messaging software is relatively mature. Therefore, the function is well listed. The best way to describe features at a glance is the use case diagram. However, the tragedy is that the company disabled the port and could not upload images. An evil company. So here is a simple list.

Function list:

  • Chat: This includes three methods (voice chat, video chat, and text chat ). It is extended to two occasions (single-person, multi-person ). Text Chat includes text, emojis, and images. The expressions can be expanded to basic and custom expressions.
  • Transmission: There are two types of extensions: file transmission and folder transmission. The functions include online transmission and offline transmission. Resumable upload is also required.
  • Channel: in fact, this and chat should belong to the following two functional points. It can also be said that, similar to multi-user chat, the only difference is weak management. The user can apply for an account and publish relevant information on the channel to which the account is assigned. Other users can search for the channel to enter the station, and then accept the Information and Support interaction.
  • In terms of peripherals, Hardware includes mobile and PC access programs. That is, users can use mobile phones, tablets, and PCs to log on.

The function list has been listed. The following describes how to deploy the software structure. So his deployment is as follows:

  • Client: the user access program. Through the access program, you can implement all the above functions. This includes the pc version, tablet version, and mobile phone version. It also needs to adapt to a large number of types. The workload should not be underestimated, but in general, his development strategy is of the original type, and one write is everywhere. The so-called adaptation is to change and modify.
  • Server: processes necessary background information, such as authentication and Information Registration during user login. Because the server does not need to adapt to different models. What is used by the server is what we say, and end users do not care about it. Therefore, you can specify either windows or linux at the initial stage. Windows is tentative here. Here, the applicable development strategy is iterative. Because of the wide range of functions, please iterate slowly. I personally do not think that iteration is agile development. It may be due to my personal rejection of agility. I always think that this is a liar. Especially when I see agile development exchanges, my personal feeling is no different from pyramid schemes.

The general framework of Instant Messaging deployment is also mentioned. Now, let's look at the technical difficulties. Some functional points that will not spread are not difficult. Just do it. Therefore, in the initial stage of software design, we should consider the difficulties that are easy to expand globally, just like cancer is in the blood. Don't fix it, and be careful when the whole body crashes. Some nails are black and so on. You just need a knife and put it next to it. You just need to pick it up one day. However, although some will spread throughout the body, but helpless, personal feeling should not exist on the line, anyway, no moves.

Instant messaging, the first problem on the Internet, is the load problem. After all, the server's capabilities are limited. At this time, we have to consider the first server to be specialized, that is, more servers and their respective roles. The important thing is to clarify their responsibilities. As a result, several servers emerged. The first one was specifically used to receive user logins, and was responsible for authentication and database updates. The second is responsible for communication, that is, users and users want to talk to each other. Because of network problems, they can't say it themselves, so they found a transfer station. However, the load problem still exists. The communication server is unable to cope with the increasing number of customers and the large amount of communication. So I came up with two solutions. The first is to solve the problem and build clusters and a large number of transit servers, but the bottleneck still exists. The second is traffic distribution. If the communication server does not pass the communication server, do not go through the communication server. So I thought of P2P. The cost-effective solution is P2P, although its implementation has some requirements for the network.

The entire software structure is clear. It mainly includes two parts: client and server. Server: logon server and communication server. The procedure of a specific session is described as follows.

  • Login: the user first logs on to the server, indicating that he is online. The user connects to the specified port of the login server to initiate a login request. The request carries the necessary authentication information. Log on to the server to find the authentication server for authentication, and redirect to the processing policy based on the authentication result. If the authentication succeeds, a unique valid SESSIONID is generated (one part of the SESSIONID is composed of a unique user ID), and the connection information and the ID are packaged and delivered to the database server, the status bits are marked as logon, the database server is responsible for warehouse receiving operations, the tables saved are status tables, and whether the warehouse receiving is successful is returned. The logon server continues to redirect to the processing policy based on the returned results of the database server. If the logon succeeds, the system returns the message indicating successful logon to the user and carries the server connection information and SESSIONID in the message body. If the response fails, the client server is busy. Try again later. The Database Server regularly scans the status table. If the table is in a non-online status for more than 30 seconds, the record is deleted.
  • Connection: the user receives the result returned by the login server. If the result fails, the user is prompted directly. The process is complete. If the connection succeeds, the system obtains information about the connection server from the message body, releases the connection with the login server, and uses the previous port to try the connection with the connection server. The connection fails, prompt the user for network timeout. If the connection is successful, a connection request is sent. The message body carries the SESSIONID. After the connection server receives a remote connection, it first marks its socket as uninitialized. When receiving a connection request from a customer, it returns the SESSIONID from the message body, then, package the client connection information and SESSIONID to the database server for further legality check. If the database server finds that they are consistent, the response is valid; otherwise, the response is invalid. The connection server performs a Redirection policy based on the response from the database server. If an illegal connection is received, the client connection is forcibly interrupted. The client prompts a user service exception after the connection is forcibly interrupted. If valid, change the SOCKET status to connection. Then, send a command to the database server to query the user information corresponding to the SESSIONID, such as the friend list, profile picture, and personalized signature. The message contains online friends and the database server receives the message, first, update the status of the previous record to online, query the relevant table, and pack the queried information and return it to the Connected Server. The connection server receives the information and forwards it to the user. The Database Server periodically scans the status table and connects to the server to ensure client information synchronization.
  • When a user needs to initiate a session, the user first initiates a session request information for the connection server. The connection server sends A Response Message to A, and the message body carries the connection information of the Communication Server. After receiving A message, A establishes a tcp connection to the communication server based on the information in the message body.
  • The message carries the unique ID of the user who needs the session. The connection server queries the status table based on the unique ID. If the table exists, the user to be connected is online. The request message is directly forwarded to the Communication Server. The communication server notifies user B of the session request information, and the message carries the connection information of user. B initiates A UDP packet directly to A after receiving the message, and the message body is empty. Then, B sends the response to the communication server. The communication server notifies A that A can start A session with B. UDP and TCP use the same port. If B is not online, message A is sent to send the information directly to the Communication Server. The communication server is responsible for saving the information locally. When B is online, it will be forwarded again. The storage time can be set.
  • Offline. A. disconnect from the Connected Server. The connection server sends a command to the database server to update the status table. The status is offline. The Database Server periodically scans the status table and triggers the corresponding process to notify the customer's friends of going online and offline, and ensures that the status table is cleaned.

Because it was written during work hours, it became a draft. I will draw a picture later. In short, the idea is clear now. The entire system includes the following places:

  • Client: Used to allow users to access the system
  • Registered server: used when a user accesses the system, providing corresponding processing such as authentication
  • Connection server: used to maintain connections with all users, notifications of status messages, and responses to information about the communication server during Client Session requests.
  • Communication Server: used for establishing communication channels and saving offline information. Including offline file transfer. You can add a file server for the communication server.
  • Database Server: Provides all database operation interfaces. All operations on the database must pass through this slot.
  • Authentication Server: available for registration servers. It is mainly used for authentication.

 

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.