Implementation of technology chat room (2)

zhaozj2021-02-08  297

Sender: LuckyBoy (Hai Xiang Sky ~ Breakbu) - Online list and user statement. Online lists can be used directly to use large object arrays, which is based on a chat room capacity. And the user's statement is directly sent to the pipeline. The definition of the online list class is as follows: Class Chaater {private static double id; // This ID is used as the difference number, and the private double socketID; // is associated with the Socket corresponding to the chat main frame. Private string nickname; // User Nickname Private String Passwd; // User Nickname Private Int PriviGe; // Private String [] filter; // A user's filter list private double login_time; // Remove login time, used to clear some Timeout join private string color; // User chat color ... // is limited to space, omitting the relevant method. } Note: Most of the above user data is in the Login phase, and the user fills in the same manner. Only SocketID wants to wait until the chat master (a normal chat interface includes chat main frame, speaking frame, three parts of the line list frame) will be obtained later. If it is more than a certain period of time, SocketID still has not been filled, indicating that the browser acquires the main framework, and the user data needs to be deleted. If you want to implement private chat like SOHU, you should also increase the properties of the user IP address. The user's definition is as follows: class content {private double timestamp; // Timestamp Private Double fromChaterid; // Speaker ID Private Double TOCHERID; // Chat Object ID Private Boolen ISSecurity; // Whether private chat Sign Private String Thecontent; // Chat content, handled in the builder, which already includes HTML text, etc. ... // Limited to the space, omitted the relevant method. } The core ThreadedChathandle class is the main process of analyzing user requests. The value of the request sent by the client, mainly there is login (verify identity, display chat room main frame), JoinChat, such as a welcome, etc., display chat content display frame, and keep the connection, send chat information.), Showtalk (Displayed Frame), Names (Show online list frame), Leave (user click button to leave the chat room), etc..

If we use the GET method to pass the data instead of submitting a form via the POST method, the user data input is transmitted in the URL. Below is a few URL instances, combined with the client process, better understand the function of the Threadedchathandle class: this Is a username password all the chat user login system of 'aaa', saying "Hello", then quit a series of requests: / login? Name = aaa & passwd = aaa / joinChat? CHATERID = 555 / showtalk? CHATERID = 555 / Names? CHATERID = 555 / speak? CHERID = 555 / Leave? CHERID = 555 ... The above is the server program process. In fact, the delivery of our parameters cannot only pass a CHATERID, and there is a corresponding authentication. Names delivers a CHATERID to update the time you visit in the online list class, avoid connection timeout. Below we look at the specific login process from the client. The chat interface consists of three frames, where JoinChat frame is a chat content display section; showTalk frame is the user input section, including chat content input, action, filtering, and management functions are in this frame; Names is an online list display section, this Part of the timing is refreshed. Let's take a look at the process of entering the chat room from the perspective of your browser.

◆ First browser request page http: // Host: 8080 / login? Name = name & passwd = PWD At this time a threadedchathandle appears (including a socket connection), and sends a line of data: get / login? Name = name & passwd = PWD HTTP / 1.1 ◆ Server generates a session ID, after verifying password, send back: http / 1.1 200 ok Content-Type: Text / HTML ... ... then threadedchathandle.start () exits, this sub-thread end ◆ After the browser receives the above HTML file, it will open in turn Three couplings (where ChaterID is the variable that needs to be passed, 555 is a virtual index): / joinChat? CHATERID = 555 / showtalk? CHATERID = 555 / Names? CHATERID = 555 The first join in these three join joinChat is entirely In the chat process, it is kept connected. This is from the browser's point of view. It is a large page that is not downloaded. The display effect is that the chat content is not updated by refresh, but constantly scroll. It can be seen by viewing HTML code, only , then the increasing chat content, no . In addition, the two coupling will be completed after the page is sent, and the thread that handles the two connections is over. Such a login chat room actually has four sub-threaded responses, but after the login is completed, only the thread that handles the JoinChat frame is still survived, which is used to receive chat information from the server, which is based on the key to the technology chat room. Of course, if the user has other operations, such as user registration, modifying nickname, modifying passwords, etc., can be a response to the class's expansion. The overloading of the class method can be easier to modify the user authentication mechanism as needed to be combined with the website other function modules.

转载请注明原文地址:https://www.9cbs.com/read-883.html

New Post(0)