The server listens to and receives information from each client and then sends it to each client server [java] package com. java. xiong. net17; import java. io. bufferedReader; import java. io. IOException; import java. io. inputStreamReader; import java. io. printStream; import java.net. socket; public class RunableSocket implements Runnable {// define Socket private Socket socket = null for processing by the current thread; // private BufferedReader read = null for the input stream used by this thread; public RunableSocket (Socket s) throws IOExc Eption {this. socket = s; read = new BufferedReader (new InputStreamReader (socket. getInputStream ();} @ Override public void run () {String line = null; try {while (line = getClentData ())! = Null) {for (Socket s: MyServer. list) {// output the information PrintStream print = new PrintStream (s. getOutputStream (); print. println (line) ;}} catch (IOException io) {io. printStackTrace () ;}// Method for reading client data public String getClentData () {String line = null; try {line = read. readLine ();} catch (IOException io) {MyServer. list. remove (socket) ;}return line ;}[ java] package com. java. xiong. net17; import java. io. IOExcep Tion; import java.net. serverSocket; import java.net. socket; import java. util. arrayList; import java. util. list; public class MyServer {public static List <Socket> list = new ArrayList <Socket> (); public static void main (String [] args) throws Exception {ServerSocket server = new ServerSocket (30001); while (true) {Socket scoket = server. accept (); list. add (scoket); new Thread (new RunableSocket (scoket )). start () ;}} Client [java] package com. java. xiong. net17; import java. io. bufferedReader; import java. io. IOException; import java. io. inputStreamReader; import java.net. socket; // print the data returned by the server out public class RubableClient implements Runnable {private Socket socket; private BufferedReader read; public RubableClient (Socket socket) throws IOException {this. socket = socket; this. read = new BufferedReader (new In PutStreamReader (this. socket. getInputStream () ;}@ Override public void run () {try {String line = null; while (line = read. readLine ())! = Null) {System. out. print (line) ;}} catch (IOException io) {io. printStackTrace () ;}} [java] package com. java. xiong. net17; import java. io. bufferedReader; import java. io. IOException; import java. io. inputStreamReader; import java. io. printStream; import java.net. socket; import java.net. unknownHostException; public class MyClient {public static void main (String [] args) throws Exception, IOException {// Send the request Socket socket = new Socket ("127.0.0.1", 30001) to the server; new Thread (new RubableClient (socket )). start (); // obtain the output stream PrintStream print = new PrintStream (socket. getOutputStream (); String line = ""; BufferedReader read = new BufferedReader (new InputStreamReader (System. in); while (line = read. readLine ())! = Null) {// print. println (line );}}}