A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
Summarize multiple web-related content in the way you like (mind Mapping, OneNote, or others).
To allow your system to be used by multiple users over the network, you need to add network functionality to your system.2.1 What network functions do you want to add to your system? What is the design idea?
A: The main is to add a
NetServer class, so that the code can be used by the client remote connection for a series of operations. To enable the system to be accessed by multiple clients at the same time, the use of TCP technology and multithreading technology is chosen. The
NetServer socket for the object is created in the class
ServerSocket , and then a class is created
ThreadServer to implement the multithreading technique, which implements the
Runnable interface and writes out the appropriate actions that the user can perform in the Run method. It then creates the thread in the main function and receives the new client continuously, thereby enabling multiple users to operate the system simultaneously.
A: The system through the network to the client or server operations carried out by the use of Io pass to the other side, the information using byte stream
OutputStream storage, and then through the character stream
PrintWriter packaging transmission.
A: Using TCP technology, the most commonly used classes in modules are TCP network traffic classes and classes
ServerSocket , as well as
Socket Multi-threading aspects of
Runnable classes and
A: The main thing is to create a NetServer class, and define its port is 9700, and then open the server in the main function to receive the client, the received client placed in a thread to be processed separately.
ThreadServerimplement the Run method in the class to set what the user can do.
The weekly code statistics need to be fused into a single table.
|Week Time||Total code Amount||New Code Volume||total number of files||number of new files|
, what is the difference between the analysis and return results? Why is there such a difference?
188.8.131.52from Shanghai, and
184.108.40.206from Xiamen City, Fujian province.
, what port number does this command connect to the remote host?
A: The default port used by the remote login service is 23, this general knowledge, of course, can also be queried by the
, try to answer: what do you see from the screen? The returned content is not
telnet cec.jmu.edu.cn 80
's homepage content? Try to use
command, what will return? See the experimental Task Book topic 1.
GET /index HTTP/1.0
Answer: See ... A dark, nothing. When the command is used
GET /index HTTP/1.0 , the source code of the school homepage is returned. This is because the Web page of the school obeys the HTTP protocol, so you use the
GET /index HTTP/1.0 send request to get the page content.
1.4 Start the Connectionwatcher, and then start a number of Internet-enabled programs (such as QQ, Telnet, browser, etc.), to see what the computer on the Internet, what port is used? What ports does QQ use to interact with those remote IPs, where are these IPs distributed? What protocols are used for communication?
A: In fact, not how to change the source code, just add a console input, and then query the IP address of Baidu to receive the information of the page.
, comparing the returned results.
telnet bbs.newsmth.net 23
2.3 Change the URL of the program to cec.jmu.edu.cn, and change the port number to 80 to see the results returned. No return results, why? How do I change the code to display properly?
choose to do:Why does it return garbled characters? How to solve?
A: As you can see, some characters do not display properly except for some coding problems, and the results are almost the same.
A: There is no return result because no
GET / HTTP/1.0\n command is used to send a request, so there is no return result, plus the following code.
Garbled mainly because the default character set on Eclipse is GBK, and the character set on the Web page is not, I first look at the source code of the Web page, it can be seen that the character set of the site is UTF-8, and then simply modify the character set on Eclipse to UTF-8. Normal display when run again
Client.java this server to send information to the client by attempting to connect to the TCP server. (Key code and run result)
Can only receive information, can be modified
So that it can interact with the server (the server can send information to Client,client can also send information to the server), write the approximate idea, do not run.
A: In general, to achieve the client-server interaction, to use the knowledge of the thread, you can create two threads in the code, implement their run method, one thread for the client to send data to the server, another thread for the servers like the client to send data.2.6 Optional: implementation 2.5. Intercept the key code and explain it.
3. ServerSocket with TCP server 3.1 simple single thread menuserver, title 3.1-3.4. (Key code and run, including the school number) can use the Network debugging assistant, set it to TCP Client (IP and port fill your menuserver IP and port), connect your menuserver. The file search function is optional.
3.2 Multi-threaded menuserver (intercept key code to prove that you are a multithreaded server, use multiple Telnet connection tests).
4. UDP Server 4.1 Retrofit 3.1 or 3.2, transforming it into UDP-based menuserver. (The key code of the TCP server that distinguishes the topic 3, need to truncate a large map, include the number, do not run the interface). You can use the Network debugging assistant to impersonate a UDP client and set it to
, to fill
Also need to fill in
4.2 Compared to the corresponding TCP-based menuserver, what is the main difference? In order to connect multiple clients, do you have to use multithreading technology? How do you differentiate between clients if you don't use them?
A: UDP is a non-connected way of exchanging data, you do not need to establish a connection before sending the data, and TCP to establish the connection before the data can be transmitted. Multithreading is required in order to connect multiple clients, or because UDP does not create a connection between the sender and the receiver, it is not possible to differentiate between different clients.5. Topic: The network program and Flow 5.1 before the program was written with a lot of knowledge of the flow. Briefly, what kind of flow should I choose when writing a network program? Java network programming, the relationship between streams. Choose a scene description, such as: simple text chat, file transfer, Application layer protocol server, such as QQ, chat rooms, online games.
A: For a network chat room, we can use the BufferedReader and bufferedwriter character streams to do the data receiving and sending operations to achieve communication between users and users. In the Java network programming, we first use the socket to create an object, and then we want to communicate between the network, it is necessary to use the various IO streams in Java, therefore, Java IO Stream is the main way of data transmission in network programming.6. Code Reading
Read the source code in the Serverandthread directory6.1 Modify the program, in the GUI interface to display their own school number, and then run the program (, the number of the study). Describe the main functions of this program.
6.2 Draw the structure diagram of the source code (dependencies of each class). and briefly describe the functions of each class.
A: The function of this program is to connect the client and the server, so that they can communicate, similar to a simple chat system. The study number was added directly to the title bar, simple and rude ...
ServerChart: interface Framework on the server side
ServerReadThread: Communicates with the client and displays the received message
ServerActionListener: Service-side action listener, adding listener events for buttons on the server interface
ClientChart: Interface Framework for clients
ClientReaderThread: communicates with the server and displays the received message
ClientListener: Client action Listener, adding listener events for Client interface buttons
MainThread: Let the client establish a connection with the server, put the thread into the list and let the server read
1. Messages received by the Client interface cannot be distinguished from who sent them.
Improved method: When sending a message on the client and the server, it is flagged who sent it.
2. Messages received by the server do not have a newline.
Improved method: Displays a newline character on the server side of your message.
3. Regardless of which end is first closed, the other end will continue to request the input stream and continuously output error messages.
Improved method: When the other end is closed, the exit request is used directly when the exception is handled
201621123031 Java Programming 13th Week of study summary
Start building with 50+ products and up to 12 months usage for Elastic Compute Service