Chat program, swing server, client for Android and swing, can communicate with each other, realize the functions such as:
Basic ideas:
Start the server:
Start the server thread, wait for the client to connect, start the broadcast thread, and send the message to the client
Starts the client thread, maintains the server's connection to a single client, and receives messages sent from the client.
Android and Swing clients:
Log in to chat: Get the input and output streams connected to the server and communicate with each other
The client is also a thread object that listens for information sent from the server and updates the interface.
Main implementation of the technology: Socket network programming, thread multithreading
The approximate flowchart is as follows:
In fact, with Android and swing client, in terms of coding is no difference, are socket communication, just The use of Android in the update interface, can not be updated through the non-main thread, because Android is threaded, the update interface must be in the main thread inside the operation, the other is only the control API is different: Swing buttons, text boxes, etc. need to be generated in code new, Controls in Android can be defined in an XML file, reducing memory usage, and virtually the interface in Android is similar to swing!!