@@ -0,0 +1,2058 @@
+package Chat_Server_4;%0A/**%0A * %0A *Version 4:%0A *Thread for Group Chat Server%0A *This time it sends all text received from any of the connected clients to all clients. %0A *This means that the server has to receive and send, and the client has to send as well as receive%0A *%0A */%0A%0Aimport java.io.BufferedInputStream;%0Aimport java.io.BufferedOutputStream;%0Aimport java.io.DataInputStream;%0Aimport java.io.DataOutputStream;%0Aimport java.io.IOException;%0Aimport java.net.Socket;%0A%0Apublic class ChatServerThread extends Thread%7B%0A%0A%09private static ChatServer server = null; %0A%09private Socket socket = null;%0A%09private static int ID = -1;%0A%09private DataInputStream streamIn = null;%0A%09private static DataOutputStream streamOut = null;%0A%09private boolean done = true;%0A%0A%0A%09public ChatServerThread(ChatServer _server, Socket _socket)%7B%0A%09%09super();%0A%09%09server = _server;%0A%09%09socket = _socket;%0A%09%09ID = socket.getPort();%0A%09%09System.out.println(%22Chat Server Thread Info: server%22+ server + %22 socket %22+ socket + %22 ID %22+ ID);%0A%09%7D%0A%0A%09public static void send(String msg)%7B%0A%09%09try%7B%0A%09%09%09streamOut.writeUTF(msg);%0A%09%09%09streamOut.flush();%0A%09%09%7D%0A%09%09catch(IOException ioe)%7B%0A%09%09%09System.out.println(ID + %22 ERROR sending: %22 + ioe.getMessage());%0A%09%09%09server.remove(ID);%0A%09%09%09ID=-1;//set ID -1 for the thread...%0A%09%09%7D%0A%09%7D%0A%0A%09public int getID()%7B%0A%09%09return ID;%0A%09%7D%0A%0A%09public void run()%7B%0A%09%09System.out.println(%22Server Thread %22 + ID + %22 running.%22);%0A%09%09while(ID!=-1)%7B%0A%09%09%09try%7B%0A%09%09%09%09server.handle(ID, streamIn.readUTF()); %0A%09%09%09%7D%0A%09%09%09catch(IOException ioe)%7B%0A%09%09%09%09System.out.println(ID + %22ERROR reading: %22 + ioe.getMessage());%0A%09%09%09%09server.remove(ID);%0A%09%09%09%09ID=-1;//set ID to -1 so it will not enter the loop again instead of deprecated stop()%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09public void open() throws IOException%7B%0A%09%09streamIn = new DataInputStream(new BufferedInputStream(socket.getInputStream()));%0A%09%09streamOut = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));%0A%09%7D%0A%0A%09public void close() throws IOException%7B%0A%09%09if(socket != null)%7B%0A%09%09%09socket.close();%0A%09%09%7D%0A%09%09if(streamIn != null)%7B%0A%09%09%09streamIn.close();%0A%09%09%7D%0A%09%09if(streamOut != null)%7B%0A%09%09%09streamOut.close();%0A%09%09%7D%0A%09%7D%0A%7D%0A

Create ChatServerThread.java