Originally this homework I want to make a graphical interface, but the reality is that I understand test instructions wrong, and then lost the initial interest, or the program into a function of the correct but "UI" unfriendly console, but no matter how, the development of the pre-graphic interface is very rewarding, after all, to tell the truth, It is not easy to make a tangible color of Java, and with the help of visual plugins Windowsbuilder, the process is exciting and tiring.
OK, but the graphical interface has become a history, now say the right console
I also just know that in eclipse, you can run multiple programs, as long as you have a. java file with public static void main, he can give you a window to let you run up. However, these windows are stacked together and need to choose a different window for IO operation.
The general idea is to use the C/S method, the client through the socket to the server to send and accept the two work, of course, in order to reflect the real situation of the characteristics of the duplex, send and receive is required to open two threads, that is, a user needs to manage two threads. The server is relatively complex because it involves scheduling, and the server needs to have a thread that sends messages to the online client (the one thing that the thread has to do is send the message to all the user's windows whenever there is a message). And the thread that accepts the message from the client (what this thread is doing is handing over the received message to the thread that sent the message, so the communication problem between the two threads is also a key to the implementation), in order to make all the user messages synchronous, The server needs to manage a list of user threads to control the behavior of the user, which requires that whenever a user requests a connection to a server, the server will create a new thread for the user, so what is the connection between client and server, and that is our socket.
Java Socket multithreaded Chat room