Java Socket multithreaded Chat room

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.