private void joinGame() throws IOException {

		processCommand(Operation.JOIN_GAME);
		// Wait for an ack to know which port to finally communicate with.
		byte[] receiveData = new byte[1024 * 100];
		DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
		clientSocket.receive(receivePacket);
		ip = receivePacket.getAddress();
		port = receivePacket.getPort();

		// Starting a separate thread for listening to updated grids.
		Thread listen = new Thread(new Runnable() {

			@Override
			public void run() {
				while (isRunning()) { // Iterate until LEAVE_GAME is received.
					Object grid = Utility.receiveMessage(clientSocket);
					if (grid == null) {
						shutDown();
					} else if (grid instanceof Command.Operation) {
						Command.Operation c = (Command.Operation) grid;
						if (c == Command.Operation.LEAVE_GAME) {
							shutDown();
						} else {
							if (!isStarted()) {
								setStarted(true);
							}
						}
					} else { // we need to refresh the grid.
						if (!refreshSinceLastCommand) {
							logger.logCommandLatency(lastCommand);
							refreshSinceLastCommand = true;
						}
						if (showGui) {
							synchronized (lock) {
								if (bc == null) {
									bc = new BombermanClient((Square[][]) grid);
									bc.setVisible(true);
								} else {
									if (grid instanceof Square[][]) {
										bc.refresh((Square[][]) grid);
									}
								}
							}
						}
					}
				}
			}

		});

		listen.start();

	}