diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-02-18 08:10:10 -0500 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-02-18 08:10:10 -0500 |
commit | b4dbd2cfa724476162fa6d35941a5d7cdc9c9524 (patch) | |
tree | 431af0b75efa29dfa3bab2868a78ab0eb29173c7 /CS2452/chat | |
parent | e8b1808eaf87a49e4c34ebbfb66854baa627418c (diff) |
Adds all assignments not previously in a git repo
Diffstat (limited to 'CS2452/chat')
-rw-r--r-- | CS2452/chat/ChatClient.java | 47 | ||||
-rw-r--r-- | CS2452/chat/ChatServer.java | 44 |
2 files changed, 91 insertions, 0 deletions
diff --git a/CS2452/chat/ChatClient.java b/CS2452/chat/ChatClient.java new file mode 100644 index 0000000..816d097 --- /dev/null +++ b/CS2452/chat/ChatClient.java @@ -0,0 +1,47 @@ +import java.util.*; +import java.io.*; +import java.net.*; + +class ChatClient +{ + public static void main(String[] args) + { + Socket s; + BufferedReader br, tr; + BufferedWriter bw; + InetAddress address = null; + int port = 0; + + tr = new BufferedReader(new InputStreamReader(System.in)); + + try{ + address = InetAddress.getByName(args[0]); + port = Integer.parseInt(args[1]); + }catch (UnknownHostException ex) + { + ex.printStackTrace(); + } + + try + { + System.out.printf("Connecting...\n"); + s = new Socket(address, port); + + br = new BufferedReader(new InputStreamReader(s.getInputStream())); + + bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); + System.out.printf("Client>"); + + while(true) + { + bw.write(tr.readLine()); + bw.newLine(); + bw.flush(); + System.out.printf("%s: %s\n%s>", "Server", br.readLine(), "Client"); + } + } catch (Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/CS2452/chat/ChatServer.java b/CS2452/chat/ChatServer.java new file mode 100644 index 0000000..3259611 --- /dev/null +++ b/CS2452/chat/ChatServer.java @@ -0,0 +1,44 @@ +import java.io.*; +import java.util.*; +import java.net.*; + +class ChatServer +{ + public static void main(String[] args) + { + ServerSocket ss; + Socket s; + BufferedReader br, tr; + BufferedWriter bw; + + tr = new BufferedReader(new InputStreamReader(System.in)); + + try + { + ss = new ServerSocket(2452); + + s = ss.accept(); + System.out.printf("Client connected...\n"); + + + br = new BufferedReader(new InputStreamReader(s.getInputStream())); + bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); + + //String[] address = new String[2]; + //address[0] = InetAddress.toString(s.getAddress()); + //address[1] = InetAddress.toString(s.getLocalAddress()); + + while(true) + { + System.out.printf("%s: %s\n%s>", "Client", br.readLine(), "Server"); + bw.write(tr.readLine()); + bw.newLine(); + bw.flush(); + } + + }catch (Exception e) + { + e.printStackTrace(); + } + } +} |