diff options
| author | O'Shea <osheas1@wit.edu> | 2020-12-10 14:03:54 -0500 |
|---|---|---|
| committer | O'Shea <osheas1@wit.edu> | 2020-12-10 14:03:54 -0500 |
| commit | cca61c9f562d2c9e2be13ec16abe134d209b54e3 (patch) | |
| tree | 3f957b579c45d0536e7e1740acdb0cdbc773f9f4 /src/javaChat/ChatClient.java | |
| parent | 690bbba9550e2644e48db44fb94d4df86494a34e (diff) | |
Final implementation, ready for presentation!
Diffstat (limited to 'src/javaChat/ChatClient.java')
| -rw-r--r-- | src/javaChat/ChatClient.java | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/src/javaChat/ChatClient.java b/src/javaChat/ChatClient.java deleted file mode 100644 index 9560b49..0000000 --- a/src/javaChat/ChatClient.java +++ /dev/null @@ -1,94 +0,0 @@ -package javaChat; - -import java.net.* ; - -import javax.swing.JFrame ; - -import java.io.* ; - -public class ChatClient - { - - /** - * - * - * @param args - * @throws IOException - */ - public static void main( String[] args ) throws IOException - { - - // Get server IP - BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) ) ; - System.out.print( "\nPlease enter the IP of the desired server: " ); // GUI: IP BOX - - String serverIP = keyboard.readLine() ; - - // Open your connection to a server, at port 6789 - Socket socket = new Socket( serverIP , 6789 ) ; - - // Create communication streams - DataInputStream dataStreamIn = new DataInputStream( socket.getInputStream() ) ; - DataOutputStream dataStreamOut = new DataOutputStream( socket.getOutputStream() ) ; - - // Establish connection, make user-name - System.out.print( "\nConnection established,\nPlease enter a username: " ) ; - String username = keyboard.readLine() ; - dataStreamOut.writeUTF( username ) ; - - ///////////////////////// - //// Program Running //// - ///////////////////////// - - // Thread for sending messages - Thread sendMessage = new Thread(new Runnable() - { - @Override - public void run() - { - System.out.print( "\n-= Type /help for a list of commands =-" ) ; - while( true ) - { - try - { - String messageOut = keyboard.readLine() ; - dataStreamOut.writeUTF( messageOut ) ; - } - catch( IOException x ) - { - x.printStackTrace() ; - System.exit( 0 ) ; - } - } - } - }) ; - - // Thread for receiving messages - Thread receiveMessage = new Thread( new Runnable() - { - - @Override - public void run() - { - while( true ) - { - try - { - String messageIn = dataStreamIn.readUTF() ; - System.out.printf( "%n%s\n", messageIn ) ; - } - catch( IOException x ) - { - x.printStackTrace() ; - System.exit( 0 ) ; - } - } - } - }); - - // Begin threads - sendMessage.start() ; - receiveMessage.start() ; - } - } - // end class ChatClient
\ No newline at end of file |
