First, the purpose and requirements of the experiment:
Objective: to write a small Java chat room system and master the advanced application programming skills of Java network communication, multithreading, IO file operation and so on.
Requirements: Based on the fifteenth chapters of the book Java, the source code of the network communication examples 15.3 and 15.4, we compile a small C/S Java chat room system based on TCP socket socket.
The following functions are completed:
1, multi client mode, to realize the individual communication between customers and customers, and request information to transfer through the server (50 points)
2, end to end communication, to achieve parallel communication mode (no more than you say, I say, one end of the information transmission is not affected by the other side) (30 points).
3. Implement end to end file transfer (20 points)
4. Add a graphical interface.
two, experimental steps
1, the TCP socket socket C/S program is supported by the single client for the operation of the textbook example.
Build Java project on this machine, run client and server program separately, switch client / server console, input chat message alternately, experience client / server chat conversation process.
Modify the server address of the client socket connection, run the client and the server program on two different machines, enter the chat message alternately on the console of the two machines, and experience the chat / dialogue process of the client / server on different machines.
Start a server program, start the two client program, input chat messages on two client console, observe the operation results of the server console, at this time, the server side program can only support the first client request.
2, run the TCP socket socket C/S program that supports multiple customers in the textbook example.
Build Java project on this machine, start a server program, start two client programs, enter chat messages on the console, and experience the client / server chat dialogue process supporting many clients.
Modify the server address of the client socket connection, run the client on one of the two different machines, run the server program on one machine, enter the chat message on the console of each machine, and experience the multi client / server chat and dialogue process on different machines.
3. Understanding example 15.4's principle of multi client / server programming based on TCP socket socket, here
On the basis of this, write a communication program that supports the client to the client, and requires information to be transferred through the server.
Hint: the customer login to the server, the server receives the connection request, distributes the corresponding customer service thread, and the thread saves the socket of the customer to use for later communication.
The client sends messages to another customer, in essence, the client sends messages to the server through the socket connected to the server. The server's customer service thread receives the message and transmits the message to the target customer through the socket connected to the destination client.
4. On the basis of the third step program, the parallel communication mode is implemented.
Hint: a different thread can be used to receive and send messages
5. Implement end to end file transfer
Tip: the client sends the local file byte stream, sends it to the server through the socket, and the server transfers the file byte stream to the client receiving terminal. The client receives the byte stream from the socket and writes it to the local file.
6. Adding a graphical interface to the above functions, using the Swing container and the event processing mechanism (selected)