import java.awt.*; import java.net.*; import java.io.*; import java.awt.event.*; public class Irc { Frame f; TextArea ta; TextField tf; Socket toServer; private InputStream is; private DataInputStream dis; private OutputStream os; private DataOutputStream dos; String serverName = "irc.fun.uni.net"; int port = 6666; public static void main(String args[]) { try { Irc i = new Irc(); } catch(IOException e) { System.out.println("Errore nell connessione"); System.exit(0); } } public Irc() throws IOException{ try{ toServer = new Socket(serverName, port); is = toServer.getInputStream(); dis = new DataInputStream(is); os = toServer.getOutputStream(); dos = new DataOutputStream(os); } catch(IOException e) { toServer.close(); dos.close(); dis.close(); throw e; } dos.writeBytes("NICK fabuio\n"); dos.writeBytes("USER fabuio stud26 stud26 :Fabio F.\n"); dos.writeBytes("JOIN #bassano\n"); f = new Frame("Client Irc"); f.setSize(300,600); ta = new TextArea(); f.add(ta); tf = new TextField(); tf.addActionListener(new MyText(dos, tf, ta)); f.add(tf, BorderLayout.SOUTH); f.setVisible(true); byte b; while(true) { b = dis.readByte(); ta.appendText("" + (char)b); } } } class MyText implements ActionListener { private DataOutputStream dos; private TextField tf; private TextArea ta; public MyText(DataOutputStream dos, TextField tf, TextArea ta) { this.dos = dos; this.tf = tf; this.ta = ta; } public void actionPerformed (ActionEvent ae) { try { dos.writeBytes(tf.getText() + "\n"); } catch (IOException e) { } ta.appendText(tf.getText()); tf.setText(""); } }