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
| static int port1=1990;
static String adr="localhost";
static ServerSocket s;
static Socket s1;
//static Socket con;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
s=new ServerSocket(port);
s1=new Socket(adr,port1);
while(true){
System.out.println("serveur p2 en atttente");
Socket con=s.accept();
ObjectInputStream in=new ObjectInputStream(con.getInputStream());
String n=(String)in.readObject();
System.out.println("entrez un entier");
Scanner e=new Scanner(System.in);
int m=e.nextInt();
/*Connection avec C3*/
ObjectOutputStream out=new ObjectOutputStream(s1.getOutputStream());
out.writeObject(n);
out.writeObject(Integer.toString(m));
/*renvoi de la notification a P1*/
ObjectInputStream i=new ObjectInputStream(s1.getInputStream());
String ch=(String)i.readObject();
ObjectOutputStream out1=new ObjectOutputStream(con.getOutputStream());
out1.writeObject(ch);
//ObjectInputStream i1=new ObjectInputStream(s1.getInputStream());
String fact=(String)i.readObject();
String produit=(String)i.readObject();
ObjectOutputStream out2=new ObjectOutputStream(con.getOutputStream());
out2.writeObject(fact);
out2.writeObject(produit);
}
}
} |
Partager