예제 #1
0
  public void begin() {
    global = (FreeMMGNetwork) this.network;

    int total_width = global.getAsInt("cell_width") * global.getAsInt("world_width");
    int total_height = global.getAsInt("cell_height") * global.getAsInt("world_height");

    ia = new IA[global.getAsInt("NUM_PLAYERS")];
    myId = new int[global.getAsInt("NUM_PLAYERS")];
    ownerCell = new int[global.getAsInt("NUM_PLAYERS")];
    downloadEstimative = new int[global.getAsInt("NUM_PLAYERS")];
    uploadEstimative = new int[global.getAsInt("NUM_PLAYERS")];

    int idBase = global.getAsInt("WHN") + 1 + 1;
    for (int k = 0; k < global.getAsInt("NUM_PLAYERS"); k++) {
      myId[k] = idBase + k;
      ia[k] = new IARandomWalk(total_width, total_height, 128.0);

      int[] xy = ia[k].get_pos();
      int col = xy[0] / global.getAsInt("cell_width");
      int row = xy[1] / global.getAsInt("cell_height");
      ownerCell[k] = row * global.getAsInt("world_width") + col;

      downloadEstimative[k] = 0;
      uploadEstimative[k] = 0;
    }

    ReceiveThread recv_thread = new ReceiveThread(this);
    SendThread send_thread = new SendThread(this);
    CountThread count_thread = new CountThread(this);

    recv_thread.launch();
    send_thread.launch();
    count_thread.launch();
  }
예제 #2
0
 private void getServerIPAndPort() {
   rt.running = false;
   ServerIPDialog sip = new ServerIPDialog(new JFrame(), false);
   sip.run();
   serverIP = sip.getServerIP();
   port = sip.getPort();
   connectToServer();
   rt.run();
 }
예제 #3
0
  /** Request to stop the listener/dispatch thread */
  public void stop() {
    if (receiveThread == null) return;

    receiveThread.finish();
    try {
      receiveThread.join(THREAD_WAIT_TIMEOUT);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    receiveThread = null;
  }
예제 #4
0
  public void startThread() {

    isContinueListen = true;
    handleDataThread = new HandleDataThread();
    handleDataThread.start();
    receiveThread = new ReceiveThread();
    receiveThread.start();
  }
예제 #5
0
 public void exit() {
   try {
     send(Integer.toString(exitCode));
     socket.close();
     out.close();
     in.close();
     rt.running = false;
   } catch (IOException ex) {
   }
   System.exit(0);
 }
예제 #6
0
 /** Start the listener/dispatch thread */
 public void start() {
   assert (receiveThread == null);
   receiveThread = new ReceiveThread();
   receiveThread.start();
 }