Use Java step by step to build your own chat room software (first) (Yinyin)

zhaozj2021-02-08  283

图文 并 版 至: http://www.javatwo.net/javapaper/java_chat_room.pdf

Zero ------------ Blueprios / The Plan: We will use Java to make a web chat program. This document will make a simple introduction to what is Java, and outlined the structure and way of operation of this program.

Coffee Cup 0.0.0java is a programming that Sun Microsystem launched in 1995. This language has many traditional languages. 0.0.1 In addition to some of Java's natural advantages, his greatest charm lies in the application programming interface (API, Application Programming Interface), what is the API? The so-called API refers to a functional environment to which the work environment is used to make a call or component of the system, a link library, or component. In other words, the operating system or job environment is provided to the application and system core communication interface, like : The Printf specified in ANSIC is a function call to the standard output output text. So, just know which categories are available in Java, you can easily design the Java program. 0.0.2java Language From Sun to Today, it has become a very large set of software environments, you can get the latest API specification from http://java.sun.com, as a reference to the Java program. Yes, since Java is a complete object-oriented language, his API is actually a huge category library, and the system communication with the system is packaged in each category. 0.0.3 Be Note: Java is not only a set of software, but a specification. There are many vendors to propose their own Java products based on this specification, and the program designer is designed for the Java platform, which is not a Windows program, nor the UNIX program, but a Java program. Java has developed to version 1.4.1, and currently there are IBM and Sun Microsystem on a personal computer in a personal computer. 0.0.4java's specifications can be divided into two parties: language itself specification and Java platform API is also the content of the built-in category library. These two parts have been evolved, and the expansion of the class library is quite fast. This can be seen from the size of JDK: from the 1.1 version of the 10MB to 1.4.1 version of 36 MB, the language itself has no expansion So fast: It is expected that the template will be supported at version 1.5. 0.0.5 There is no doubt that Java's development will become more interesting.

Introduction to the blue sky 0.1.0, streamlined the network: through the cable, fiber or radio, connect the electronic support facility, so that the network can be configured by transmitting the media exchange information. That information is how to pass from us to the other end? Simply, you can explain from the table below:

"Application Application Sends a message through the call application design interface. Transfer Protocol Driver Transfer Protocol Driver Accepts a request from the application, and handles its packaging to the network protocol driver, please The data is sent to the specified address. The network protocol driver passed the information sent by the transfer protocol driver to the network device driver, and the network device driver controls the network device hardware, and the data is sent out. Network device drivers and network hard devices direct related, responsible and hardware devices directly communicate.

Network hard devices accept commands from the device driver and send the data to the transport medium. This may be an Ethernet card, a marker ring network card, a Bluetooth device, a serial port, or a radio terminal, and the like. Transport media signals run this. This may be twisted pair, coaxial core cable, fiber, water, air or vacuum, etc. Network hard equipment accepts signals from the transmission media, notify the driver after finishing: "Hello! Your goods, remember to pay." Network equipment driver receives the information and checks the information after receiving the notification of network hard devices. Send the information to the network protocol driver. After the network protocol driver gets the information sent by the network device, the network protocol driver will look at what is going to give him. If not, you will lose the information, or it will be handed over to the transfer protocol driver. . The transfer protocol driver receives the information sent by the network protocol driver, and the data is handed over to the application. Application Application Number is obtained through a repying application design interface. "

0.1.1java currently only knows this network type of IP (Internet Protocol), and two transmission communication protocols of TCP and UDP. The Internet (Internet) is using the IP network communication protocol. 0.1.2TCP and UDP have some differences, three of the biggest differences are: TCP will definitely send the information will definitely send, if the application will notify the application, and UDP does not have this guarantee, send out information is like Broken line of kite. TCP also guarantees that the order is the same as the sequence of transmission, that is, if your program first packages the data package to send it, the package is wrapped out, the other end will first receive the first package. B is wrapped, and UDP does not provide such a guarantee. Because TCP provides various guarantees for the transfer of information, the burden of TCP is added to the network is more slower than the UDP, and the speed will naturally slow.

0.1.3 Most of the programs are using TCP / IP as a communication protocol, which can save the problem of information integrity and continuity. If your program does not need these two features, then you can consider Using UDP / IP as a network data transmission medium for your program. 0.1.4 Basically, because there is an application interface package, through the network access information is like reading and writing a file, it is quite simple. 0.1.5 Back to the Java language itself, the following listings are listed below:

Category: =========== is a collection of data domains and methods used to process these materials, a category uses keyword class with category access level, category The inheritance status of the name and category is announced. To generate an object entity according to a category, you must use the keyword NEW and add the category name and constructive parameters to be generated, and the generated item is called an object (Object) or a case called this category (Instance) ), Such as: Button str = new button;, Str is a case of Button or a STR is an object of a Button category.

Inheritance: ====== Java supports the inheritance of the object, inherits a category as long as you use the Extends keyword to add the estimated category name.

Abstractical method: ======================= Abstract method is the pure virtual function in C , to declare the abstract method as long as the declaration method Key words Abstract. Abstract category: ==================== A category If you have more than one abstract method, he is an abstract category. Abstract categories must be declared when the keyword abstract is declared. Because the abstract category is incomplete, you cannot generate an object entity of an abstract category.

Interface: ============= Java In order to avoid a category to inherit two or more problems, limit a category that can only be inherited from a category. However, this is not convenient to make a variety of features that need to have a variety of features, and the interface is born in order to make up for this. The interface is only allowed to declare constants and abstraction methods to avoid problems with name conflicts. To actually an interface, you must use the keyword IMPLEMENTS to declare a new category.

Deprecated: ============== In the process of Java evolution, some standard categories will be renamed or discarded because some reasons are maintained, these Most of the methods will remain in the standard kit, but it is not recommended to use them. The API specification will list alternative new methods or solutions next to the abandoned method.

0.1.6java language itself The structure and grammar Please refer to the Javalanguage Specification provided by SUN Microsystem provided by SUN Microsystem.

Carbon pencil 0.2.0 Good, let's take a look at the chat room program we have written out by us. Here is the interface I think:

0.2.1 How do I transmit it? There are many ways: star shaped, tree or cycles are feasible practices. The star-shaped architecture is relatively easy to manage, so we will use this structure, the following is a schematic diagram of the star architecture:

0.2.2 The server and user-end programs will say something to achieve the purpose of letting users chat? Here is the content I think, of course you can have you: First of all, the terminal user connects the server, and the server says: "As early as a certain.", Then, as long as there is a message to send the server, The server will transfer this message to all people who take the line, including people who send messages.

0.2.3 In other words, we will manage the user-ended content management rights to manage the content management rights of the message window to manage, so that you can make sure that members in all chat indoors will see the same content. One, the user-end program is connected to the server, the first sentence of the user's program is to indicate that it is your identity. Every sentence will be transferred to all users hung on that server. If the user ends says the server, the server is said to the message window to the message window.

0.2.4 Synthesizes the above mentioned that we will write two sets of procedures: the program of the user and the server. The entire chat room requires two groups of procedures to operate simultaneously to work well. Among them, the user's program will have a beautiful graphical user interface (GUI) to make it easy for the terminal user. As for the server, everything is from simple, after all, it is the core of the entire system, and there is no error existing. Zero: End of blueprints (continued)

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

New Post(0)