1 package edu.upv_ehu.gb.clientServerProtocol;
2
3 import java.io.*;
4 import java.net.*;
5
6 public class Client {
7
8 public static void main(String[] args) throws UnknownHostException, IOException {
9 Socket s = new Socket("127.0.0.1", 6000);
10 ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
11 ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
12
13 //Atención a las respuestas del servidor
14 new Thread() {
15 {setDaemon(true);start();}
16
17 public void run() {
18 try {
19 while (true) {
20 Protocol p = (Protocol) ois.readObject();
21 System.out.println(p.mensaje + " //mensaje recibido de " + p.nick);
22 }
23 } catch (Exception ignore) {}
24 }
25 };
26
27 //Lectura del teclado y envío al servidor.
28 BufferedReader teclado = new BufferedReader(new InputStreamReader(System.in));
29 String q;
30 do {
31 q = teclado.readLine();
32 oos.writeObject("exit".equals(q.toLowerCase()) ? null : new Protocol("Yo", q));
33 } while (!"exit".equals(q.toLowerCase()));
34
35 }
36 }
37