/**
* ChatClient.java 1.00 96/11/07 Merlin Hughes
*
* Copyright (c) 1996 Prominence Dot Com, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* for non-commercial purposes and without fee is hereby granted
* provided that this copyright notice appears in all copies.
*
* http://prominence.com/ [email protected]
*/
public ChatClient (String title, InputStream i, OutputStream o) { super (title); this.i = new DataInputStream (new BufferedInputStream (i)); this.o = new DataOutputStream (new BufferedOutputStream (o));
setLayout (new BorderLayout ());
add ("Center", output = new TextArea ());
output.setEditable (false);
add ("South", input = new TextField ());
pack ();
show ();
input.requestFocus ();
listener = new Thread (this);
listener.start ();
}
public static void main (String args[]) throws IOException { if (args.length != 2) throw new RuntimeException ("Syntax: ChatClient <host> <port>");
Socket s = new Socket (args[0], Integer.parseInt (args[1])); new ChatClient ("Chat " + args[0] + ":" + args[1],
s.getInputStream (), s.getOutputStream ());
}
}
////////
/**
* ChatApplet.java 1.00 96/11/01 Merlin Hughes
*
* Copyright (c) 1996 Prominence Dot Com, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* for non-commercial purposes and without fee is hereby granted
* provided that this copyright notice appears in all copies.
*
* http://prominence.com/ [email protected]
*/
/**
* ChatHandler.java 1.00 96/11/07 Merlin Hughes
*
* Copyright (c) 1996 Prominence Dot Com, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* for non-commercial purposes and without fee is hereby granted
* provided that this copyright notice appears in all copies.
*
* http://prominence.com/ [email protected]
*/
public class ChatHandler extends Thread { protected Socket s; protected DataInputStream i; protected DataOutputStream o;
public ChatHandler (Socket s) throws IOException { this.s = s;
i = new DataInputStream (new BufferedInputStream (s.getInputStream ()));
o = new DataOutputStream (new BufferedOutputStream (s.getOutputStream ()));
}
///////////
/**
* ChatServer.java 1.00 96/11/07 Merlin Hughes
*
* Copyright (c) 1996 Prominence Dot Com, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* for non-commercial purposes and without fee is hereby granted
* provided that this copyright notice appears in all copies.
*
* http://prominence.com/ [email protected]
*/
public class ChatServer { public ChatServer (int port) throws IOException {
ServerSocket server = new ServerSocket (port); while (true) {
Socket client = server.accept ();
System.out.println ("Accepted from " + client.getInetAddress ());
ChatHandler c = new ChatHandler (client);
c.start ();
}
}
public static void main (String args[]) throws IOException { if (args.length != 1) throw new RuntimeException ("Syntax: ChatServer <port>"); new ChatServer (Integer.parseInt (args[0]));
}
}