views:

43

answers:

0

Hi, i got a problem with my network. I can send a file with my network but it is just a test. But I want to insert the network in my connect4.

My connect4 is actually an array. And I just need to recup the column with the network and tell this to the client or to the server each time i set a piece and upload the information.

Here are differents part of the code involved.


public void actionPerformed(ActionEvent e) {
        for (int i = 0; i tabButton.size(); i++) {
            JButton button = tabButton.get(i);
            if (e.getSource() == button) {

                partie.getTour().placerPion(i + 1, partie);
                refresh();

            }
        }

It is the action listener that recup the column


public class TransfertFichierClient {

    protected BufferedReader SocketReader;
    protected PrintWriter socketWriter;
    protected String hostIp;
    protected int hostPort;

    public TransfertFichierClient(String ip, int port){
        hostIp = ip;
        hostPort = port;
    }

    public void ouvrirConnexion(){
        try{
            Socket client = new Socket(hostIp, hostPort);
            SocketReader = new BufferedReader(new InputStreamReader(client.getInputStream()));
            socketWriter = new PrintWriter(client.getOutputStream());
        }
        catch(IOException e){
            System.out.println("Problème d'initialisation du socket :"+e);
        }
    }

    public void afficheFichier()
    {
        try{
            socketWriter.println("5");
            socketWriter.flush();
            String s;
            while((s = SocketReader.readLine()) != null) 

                System.out.println(s);      
        }
        catch(Exception e){
            System.out.println("Problème de lecture dans ");}
    }

    public void fermerConnexion(){
        try{
            socketWriter.close();
            SocketReader.close();
        }
        catch(IOException e){
            System.out.println("Problème d'initialisation du socket :"+e);
        }
    }
}


this is the client


public class TransfertFichierServeur {

    int portEcoute;
    public TransfertFichierServeur (int port) {
        portEcoute=port;
        }


    public void accepteConnexions(){
        try{
            ServerSocket serveur = new ServerSocket(portEcoute);
            Socket connexion = null;
            System.out.println("Serveur de fichier pret");
            while(true){
                connexion = serveur.accept();
                traiteConnexion(connexion);
            }
        }
        catch(IOException e){
            System.out.println("Impossible d'initialiser un socket sur le port:"+portEcoute);
        }
    }

    public void traiteConnexion(Socket conduitClient){
        try{
            BufferedReader flotVenantDeClient = new BufferedReader(new InputStreamReader(conduitClient.getInputStream()));
            String s = flotVenantDeClient.readLine();
            System.out.println(s);
            //BufferedReader flotVenantDeFichier = new BufferedReader(new FileReader(new File(flotVenantDeClient.readLine())));
            PrintWriter flotVersClient = new PrintWriter(conduitClient.getOutputStream());
            String ligne = null;
            /*while((ligne = flotVenantDeFichier.readLine()) != null){
                flotVersClient.println(ligne);
            }
            flotVenantDeFichier.close();*/
            flotVersClient.println("2");
            flotVersClient.flush();
            flotVenantDeClient.close();
            flotVersClient.close();
        }
        catch(Exception e){
            System.out.println("Erreur au cours du traitement d'un client:"+e);
        }
    }
}

this is the server

public Plateau(int row, int column, String joueur1, String joueur2,boolean isIA1, boolean isIA2,String color1, String color2)

This is constructor's parameters of my main window.

thanks for help.