Package com.rila.chat.client

Source Code of com.rila.chat.client.Client

package com.rila.chat.client;

import java.io.IOException;
import java.util.Scanner;

import fr.cesi.chat.domain.Statut;
import fr.cesi.chat.domain.User;

public class Client {

  private ClientThreadServerSendMessage clientThreadServerSendMessage;
  private ClientThreadServerResponseMessage clientThreadServerResponseMessage;
  private ClientThreadServerSendUser clientThreadServerSendUsers;
  private ClientThreadServerResponseUsers clientThreadServerResponseUsers;

  public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner(System.in);
    System.out.println("Entrez l'ip du serveur :");
    String server = sc.nextLine();
    System.out.println("Votre nom d'utilisateur :");
    String utilisateur = sc.nextLine();
    if (server.isEmpty()) {
      new Client("127.0.0.1", utilisateur);
    } else
      new Client(server, utilisateur);
    // sc.close(); // Exception in thread "Thread-1" java.util.NoSuchElementException: No line found
  }

  public Client(String ipServeur, User user) throws IOException {
    // MESSAGE
    // Pour l'envoie de message
    clientThreadServerResponseMessage = new ClientThreadServerResponseMessage(ipServeur);
    new Thread(clientThreadServerResponseMessage).start();

    clientThreadServerSendMessage = new ClientThreadServerSendMessage(ipServeur, user);
    new Thread(clientThreadServerSendMessage).start();

    // USER
    clientThreadServerResponseUsers = new ClientThreadServerResponseUsers(ipServeur);
    new Thread(clientThreadServerResponseUsers).start();

    // Pour l'envoie d'utilisateur
    clientThreadServerSendUsers = new ClientThreadServerSendUser(ipServeur, user);
    new Thread(clientThreadServerSendUsers).start();

  }

  public Client(String ipServeur, String utilisateur) throws IOException {
    User user = new User(utilisateur, Statut.EN_LIGNE, null);

    // MESSAGE
    // Pour l'envoie de message
    clientThreadServerResponseMessage = new ClientThreadServerResponseMessage(ipServeur);
    new Thread(clientThreadServerResponseMessage).start();

    clientThreadServerSendMessage = new ClientThreadServerSendMessage(ipServeur, user);
    new Thread(clientThreadServerSendMessage).start();

    // USER
    clientThreadServerResponseUsers = new ClientThreadServerResponseUsers(ipServeur);
    new Thread(clientThreadServerResponseUsers).start();

    // Pour l'envoie d'utilisateur
    clientThreadServerSendUsers = new ClientThreadServerSendUser(ipServeur, user);
    new Thread(clientThreadServerSendUsers).start();

  }

  public ClientThreadServerSendUser getClientThreadServerSendUsers() {
    return clientThreadServerSendUsers;
  }

  public ClientThreadServerSendMessage getClientThreadServerSend() {
    return clientThreadServerSendMessage;
  }

  public ClientThreadServerResponseMessage getClientThreadServerResponseMessage() {
    return clientThreadServerResponseMessage;
  }

  public ClientThreadServerResponseUsers getClientThreadServerResponseUsers() {
    return clientThreadServerResponseUsers;
  }

  public void closeConnection() {
    try {
      clientThreadServerSendMessage.getSocket().close();
      clientThreadServerSendUsers.getSocket().close();
      // clientThreadServerResponseMessage.getSocket().close();
      // clientThreadServerResponseUsers.getSocket().close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}
TOP

Related Classes of com.rila.chat.client.Client

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.