<commit_before>package ch.heigvd.res.labs.roulette.net.client;

import ch.heigvd.res.labs.roulette.data.EmptyStoreException;
import ch.heigvd.res.labs.roulette.data.JsonObjectMapper;
import ch.heigvd.res.labs.roulette.net.protocol.RouletteV1Protocol;
import ch.heigvd.res.labs.roulette.data.Student;
import ch.heigvd.res.labs.roulette.net.protocol.InfoCommandResponse;
import ch.heigvd.res.labs.roulette.net.protocol.RandomCommandResponse;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.List;
import java.util.logging.Logger;

/**
 * This class implements the client side of the protocol specification (version 1).
 * 
 * @author <NAME>
 */
public class RouletteV1ClientImpl implements IRouletteV1Client
{

  private static final Logger LOG = Logger.getLogger(RouletteV1ClientImpl.class.getName());

  protected Socket socket;


  protected String serverRead() throws IOException
  {
    return (new BufferedReader(new InputStreamReader(socket.getInputStream()))).readLine();
  }

  protected void serverWrite(String toWrite) throws IOException
  {
    PrintWriter out =
            new PrintWriter(socket.getOutputStream(), true);
    out.println(toWrite);
  }

  public RouletteV1ClientImpl()
  {
    socket = new Socket();
    LOG.info(socket.toString());
  }

  @Override
  public void connect(String server, int port) throws IOException
  {
    socket = new Socket("localhost", 1313);
    LOG.info(socket.toString());
    LOG.info(serverRead());
  }

  @Override
  public void disconnect() throws IOException
  {
    serverWrite(RouletteV1Protocol.CMD_BYE);
    socket.close();
  }

  @Override
  public boolean isConnected()
  {
    LOG.info(String.valueOf(socket.isConnected()));
    return socket.isConnected() && !socket.isClosed();
  }

  @Override
  public void loadStudent(String fullname) throws IOException
  {
    serverWrite(RouletteV1Protocol.CMD_LOAD);

    if(!serverRead().equals(RouletteV1Protocol.RESPONSE_LOAD_START))
      throw new IOException();

    serverWrite(fullname);
    serverWrite(RouletteV1Protocol.CMD_LOAD_ENDOFDATA_MARKER);

    if(!serverRead().equals(RouletteV1Protocol.RESPONSE_LOAD_DONE))
      throw new IOException();<commit_msg>soucis de connexion<commit_after>package ch.heigvd.res.labs.roulette.net.client;

import ch.heigvd.res.labs.roulette.data.EmptyStoreException;
import ch.heigvd.res.labs.roulette.data.JsonObjectMapper;
import ch.heigvd.res.labs.roulette.net.protocol.RouletteV1Protocol;
import ch.heigvd.res.labs.roulette.data.Student;
import ch.heigvd.res.labs.roulette.net.protocol.InfoCommandResponse;
import ch.heigvd.res.labs.roulette.net.protocol.RandomCommandResponse;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.List;
import java.util.logging.Logger;

/**
 * This class implements the client side of the protocol specification (version 1).
 * 
 * @author <NAME>
 */
public class RouletteV1ClientImpl implements IRouletteV1Client
{

  private static final Logger LOG = Logger.getLogger(RouletteV1ClientImpl.class.getName());

  protected Socket socket;


  protected String serverRead() throws IOException
  {
    return (new BufferedReader(new InputStreamReader(socket.getInputStream()))).readLine();
  }

  protected void serverWrite(String toWrite) throws IOException
  {
    PrintWriter out =
            new PrintWriter(socket.getOutputStream(), true);
    out.println(toWrite);
  }

  public RouletteV1ClientImpl()
  {
    socket = new Socket();
    LOG.info(socket.toString());
  }

  @Override
  public void connect(String server, int port) throws IOException
  {
    socket = new Socket(server, port);
    LOG.info(socket.toString());
    LOG.info(serverRead());
  }

  @Override
  public void disconnect() throws IOException
  {
    serverWrite(RouletteV1Protocol.CMD_BYE);
    socket.close();
  }

  @Override
  public boolean isConnected()
  {
    LOG.info(String.valueOf(socket.isConnected()));
    return socket.isConnected() && !socket.isClosed();
  }

  @Override
  public void loadStudent(String fullname) throws IOException
  {
    serverWrite(RouletteV1Protocol.CMD_LOAD);

    if(!serverRead().equals(RouletteV1Protocol.RESPONSE_LOAD_START))
      throw new IOException();

    serverWrite(fullname);
    serverWrite(RouletteV1Protocol.CMD_LOAD_ENDOFDATA_MARKER);

    if(!serverRead().equals(RouletteV1Protocol.RESPONSE_LOAD_DONE))
      throw new IOException();
{'fraction_non_alphanumeric': 0.1100196463654224, 'fraction_numerical': 0.0056756166775813145, 'mean_word_length': 4.594627594627594, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837115', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1417, 'n_words': 265}