Package pdp.scrabble.multiplayer

Examples of pdp.scrabble.multiplayer.Client


      this.check = new Thread() {
    @Override
    public void run() {
        setName("Clients alive check");
        while (threadCheck) {
      Client toRemove = null;
      try {
          sleep(TIMEOUT);
      }
      catch (InterruptedException e1) {
          //Display.error("Sleep", "Error");
View Full Code Here


  return client;
    }

    @Override
    public void disconnect(int id) throws RemoteException {
  Client client = getClientById(id);

  if (!this.runningServer) {
      this.clients.remove(client);
      this.sendMessage(
        "<Game>", this.clientsName.get(client) + " "
View Full Code Here

      else {
    this.idTurn = 0;
      }
  }

  Client client = getClientById(this.idTurn);
  String name = this.clientsName.get(client);
  client.getTurn(name);
  this.setPlayertable(idSrc, null, getGameLang("Thinking"), -1);
  this.setPlayertable(this.idTurn, null, getGameLang("Playing"), -1);
  this.sendMessage("<Game>", client.getName() + " " + getGameLang("turn."));
    }
View Full Code Here

    /** Return client with the player's id ID.
     * @param ID player id.
     * @return client corresponding to id.
     */
    private Client getClientById(int ID) {
  Client client = null;
  for (Client cl : clients) {
      if (clientsID.get(cl) == ID) {
    client = cl;
      }
  }
View Full Code Here

    }

    @Test
    public void ServerTester() throws RemoteException {
  Server server = FACTORY.createServer(1099, LANG);
  Client client = FACTORY.createClient(null, "test");

  //Connect client to server
  try {
      server.connect(null, client);
      System.out.println("Connect client to server");
View Full Code Here

    public void tearDown() {
    }

    @Test
    public void ClientTester() {
  Client client = FACTORY.createClient(null, LANG);

  // Connect without server
  try {
      client.connect(null, "localhost", "1099", "test", LANG);
      fail("Connect to inexistant server not expected");
  }
  catch (RemoteException ex) {
      System.out.println("Can't connect to null server");
  }
  catch (NotBoundException ex) {
      fail("NotBoundException was not expected");
  }
  catch (MalformedURLException ex) {
      fail("MalformedURLException was not expected");
  }

  // sendMessage without server
  try {
      client.sendMessage("Src", "Message");
      fail("Connect to inexistant server not expected");
  }
  catch (NullPointerException ex) {
      System.out.println("NullPointerException expected, can't send to null server");
  }
  catch (RemoteException ex) {
      fail("RemoteException not expected");
  }

  // Test with server
  Server server = FACTORY.createServer(1099, LANG);
  try {
      client.connect(null, "localhost", "1099", "test", LANG);
      System.out.println("Connect to localhost on port 1099");
  }
  catch (RemoteException ex) {
      fail("RemoteException was not expected");
  }
  catch (NotBoundException ex) {
      fail("NotBoundException was not expected");
  }
  catch (MalformedURLException ex) {
      fail("MalformedURLException was not expected");
  }

  // Connect with bad adress
  try {
      client.connect(null, "test", "1099", "test", LANG);
      fail("Connect to bad address not expected");
  }
  catch (RemoteException ex) {
      System.out.println("Can't connect to bad address");
  }
  catch (NotBoundException ex) {
      fail("NotBoundException was not expected");
  }
  catch (MalformedURLException ex) {
      fail("MalformedURLException was not expected");
  }

  // Connect with bad port
  try {
      client.connect(null, "localhost", "22", "test", LANG);
      fail("Connect to localhost on port 22 not expected");
  }
  catch (RemoteException ex) {
      System.out.println("Can't connect on port 22");
  }
  catch (NotBoundException ex) {
      fail("NotBoundException was not expected");
  }
  catch (MalformedURLException ex) {
      fail("MalformedURLException was not expected");
  }

  //50 connections/disconnections
  System.out.println("50 Connections/disconnections...");
  for (int i = 0; i < 50; i++) {
      try {
    client.connect(null, "localhost", "1099", "test" + i, LANG);
    server.disconnect(0);
      }
      catch (RemoteException ex) {
    fail("RemoteException was not expected");
      }
View Full Code Here

TOP

Related Classes of pdp.scrabble.multiplayer.Client

Copyright © 2018 www.massapicom. 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.