@@ -0,0 +1,2463 @@
+package com.chat.client;%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.io.PrintStream;%0Aimport java.net.URL;%0Aimport java.net.Socket;%0Aimport java.net.UnknownHostException;%0A%0Apublic class ChatClient implements Runnable %7B%0A%09// The client socket%0A%09private static Socket clientSocket = null;%0A%09// The output stream%0A%09private static PrintStream os = null;%0A%09// The input stream%0A%09private static BufferedReader is = null;%0A%09private static BufferedReader inputLine = null;%0A%09private static boolean closed = false;%0A%09public void getClient(String host,int portNumber)%7B%09%0A%09%09System.out.println(%22Welcome to the Chat room!!!!%22);%0A%09%09try %7B%0A%09%09%09clientSocket = new Socket(host, portNumber);%0A%09%09%09inputLine = new BufferedReader(new InputStreamReader(System.in));%0A%09%09%09os = new PrintStream(clientSocket.getOutputStream());%0A%09%09%09is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));%0A%0A%09%09%09URL ipAddress=new URL(%22http://checkip.amazonaws.com/%22);%0A%09%09%09BufferedReader in=new BufferedReader(new InputStreamReader(ipAddress.openStream()));%0A%09%09%09String pubIpAddress=in.readLine();%0A%09%09%09os.println(pubIpAddress);%0A%09%09%7D catch (UnknownHostException e) %7B%0A%09%09%09System.err.println(%22Don't know about host %22 + host);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09System.err.println(%22Couldn't get I/O for the connection to the host %22+ host);%0A%09%09%7D%0A%09%09/*%0A%09%09 * If everything has been initialized then we want to write some data to the%0A%09%09 * socket we have opened a connection to on the port portNumber.%0A%09%09 */%0A%09%09if (clientSocket != null && os != null && is != null) %7B%0A%09%09%09try %7B%0A%09%09%09%09/* Create a thread to read from the server. */%0A%09%09%09%09new Thread(new MultiClient()).start();%0A%09%09%09%09while (!closed) %7B%0A%09%09%09%09%09os.println(inputLine.readLine().trim());%0A%09%09%09%09%7D%0A%09%09%09%09/*%0A%09%09%09%09 * Close the output stream, close the input stream, close the socket.%0A%09%09%09%09 */%0A%09%09%09%09os.close();%0A%09%09%09%09is.close();%0A%09%09%09%09clientSocket.close();%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09System.err.println(%22IOException: %22 + e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09/*%0A%09 * Create a thread to read from the server.%0A%09 */%0A%09public void run() %7B%0A%09%09/*%0A%09%09 * Keep on reading from the socket till we receive %22Bye%22 from the%0A%09%09 * server. Once we received that then we want to break.%0A%09%09 */%0A%09%09String responseLine;%0A%09%09try %7B%0A%09%09%09while ((responseLine = is.readLine()) != null) %7B%0A%09%09%09%09System.out.println(responseLine);%0A%09%09%09%09if (responseLine.indexOf(%22Bye%22) != -1)%0A%09%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%09closed = true;%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09System.err.println(%22IOException: %22 + e);%0A%09%09%7D%0A%09%7D%0A%7D

Add client file