public void loop() throws IOException {
		acceptor = new ServerSocket(PORT);
		service  = new GLSRequestHandler(this);

		while (true) {

			System.out.println ("Waiting for connections on port " + PORT);
			//This waits for an incomming message
			socket = acceptor.accept();

			JInPiqi.request req = read_message();

			JOutPiqi.response response = null;
			GLI inst = new GLIExample(service);

			if (req.hasInit()) {
				response = inst.init(req.getInit().getUseridListList());
			} else if (req.hasHandleAction()) {
				JInPiqi.handle_action a = req.getHandleAction();
				response = inst.handle_action(a.getUserid(), a.getCommandName(), a.getCommandArgsList(), a.getState());
			} else if (req.hasHandleUserJoin()) {
				JInPiqi.handle_user_join j = req.getHandleUserJoin();
				response = inst.handle_user_join(j.getUserid(), j.getState());
			} else if (req.hasHandleUserLeave()) {
				JInPiqi.handle_user_leave j = req.getHandleUserLeave();
				response = inst.handle_user_leave(j.getUserid(), j.getState());
			} else if (req.hasHandleTimer()) {
				JInPiqi.handle_timer j = req.getHandleTimer();
				response = inst.handle_timer(j.getId(), j.getDelta(), j.getState());
			} else if (req.hasHandleTimerComplete()) {
				JInPiqi.handle_timer_complete j = req.getHandleTimerComplete();
				response = inst.handle_timer_complete(j.getId(), j.getDelta(), j.getState());
			} else {
				System.out.println("Unknown command " + req);
			}

			write_message(response);

			socket.getOutputStream().close();
			socket.close();
		}
	}