1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
package P4;
import java.net.*;
import java.io.*;
import java.util.*;
public class Client implements Runnable
{
private String adresse;
private int port;
private Socket sock;
private ObjectInputStream in;
private ObjectOutputStream out;
public Vector<Object> messages=new Vector<Object>();
public Client(String adresse, int port, String pseudo)
{
System.out.println("Adresse :"+adresse+" Port:"+port);
this.adresse = adresse;
this.port = port;
}
public void connexion()
{
try
{
sock = new Socket(adresse, port);
out = new ObjectOutputStream(sock.getOutputStream());
out.flush();
in = new ObjectInputStream(sock.getInputStream());
new Thread(this).start();
}
catch (IOException ioe)
{
System.out.println("Client fermé");
System.exit(1);
}
}
public void run()
{
while (true)
{
try {
messages=(Vector<Object>) (in.readObject());
Fenetre.go((P4.Jeton)messages.get(0),(Integer)messages.get(1),(Integer)messages.get(2));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void envoyer(Vector<Object> mess)
{
try {
out.writeObject(mess);
out.flush();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}//
}
public void quitter()
{
try
{
if (sock != null)
{
sock.close();
}
}
catch (IOException ioe)
{
System.out.println("Probleme de fermeture client");
System.exit(2);
}
}
} |