import java.io.*;
import java.net.*;

public class ClientTransfertFichier {
    public static void main(String []args) {
	try {
	    System.out.println(args[1]+" was chosen as Recepteur");
	    Socket s = new Socket(args[1],Transfert.PORT);
	    OutputStream os = s.getOutputStream();
	    byte []out = new byte[1];
	    out[0] = (byte)'R';
	    os.write(out);
	    os.flush();
	    InputStream is = s.getInputStream();
	    byte []in = new byte[2];
	    is.read(in);
	    byte [] b = s.getInetAddress().getAddress();
	    s.close();

	    System.out.println(args[0]+" was chosen as Envoyeur");
	    s = new Socket(args[0],Transfert.PORT);
	    os = s.getOutputStream();
	    out = new byte[1+4+2];
	    out[0] = (byte)'E';
	    out[1]=b[0]; out[2]=b[1]; out[3]=b[2]; out[4]=b[3]; // address
	    out[5] = in[0]; out[6] = in[1]; // port
	    os.write(out);
	    os.flush();
	    in = new byte[1];
	    is = s.getInputStream();
	    is.read(in);
	    char answer = (char)in[0];
	    if (answer!='Y') {
		System.out.println("Something's wrong...");
	    }
	} catch(Exception ex) {
	    ex.printStackTrace();
	}
    }
}