Thread currentThread = Thread.currentThread(); Packet c; while (pump == currentThread) {  c = readCommand(); if (c != null) {   switch(c.getCommand()) { case Packet.COMMAND_CLIENT_NAME : receiveClientName(c, id); break; case Packet.COMMAND_PLAYER_UPDATE : receivePlayerInfo(c); validatePlayerInfo(id); send(createPlayerUpdatePacket(id)); break; case Packet.COMMAND_ENTITY_READY : receiveEntityReady(c, id); send(createEntityPacket(c.getIntValue(0))); break; case Packet.COMMAND_PLAYER_READY : receivePlayerReady(c, id); send(createPlayerReadyPacket(id)); checkReady(); break; case Packet.COMMAND_CHAT : String chat = (String)c.getObject(0); if (chat.equalsIgnoreCase("/reset")) { resetServer(); } else { sendChatToAll(getPlayer(id).getName(), chat); } break; case Packet.COMMAND_ENTITY_MOVE : doEntityMovement(c, id); break; case Packet.COMMAND_ENTITY_ATTACK : receiveAttack(c); break; case Packet.COMMAND_ENTITY_ADD : receiveEntityAdd(c, id); resetPlayerReady(); transmitAllPlayerReadys(); break; case Packet.COMMAND_ENTITY_REMOVE : receiveEntityDelete(c, id); resetPlayerReady(); transmitAllPlayerReadys(); break; case Packet.COMMAND_SENDING_GAME_SETTINGS : gameSettings = (GameSettings)c.getObject(0); resetPlayerReady(); transmitAllPlayerReadys(); send(createSettingsPacket()); break; } }
while (receiver == Thread.currentThread()) { handle(readCommand());
		public void run() {			Thread currentThread = Thread.currentThread();			Packet c;			while (pump == currentThread) {				// get a command				c = readCommand();				if (c != null) {					//System.out.println("s(" + cn + "): received command");					// act on it					switch(c.getCommand()) {                    case Packet.COMMAND_CLIENT_NAME :                        receiveClientName(c, id);                        break;					case Packet.COMMAND_PLAYER_UPDATE :						receivePlayerInfo(c);                        validatePlayerInfo(id);                        send(createPlayerUpdatePacket(id));						break;					case Packet.COMMAND_ENTITY_READY :						receiveEntityReady(c, id);						send(createEntityPacket(c.getIntValue(0)));						break;					case Packet.COMMAND_PLAYER_READY :                        receivePlayerReady(c, id);                        send(createPlayerReadyPacket(id));						checkReady();						break;					case Packet.COMMAND_CHAT :                        String chat = (String)c.getObject(0);                        if (chat.equalsIgnoreCase("/reset")) {                            resetServer();                        } else {                            sendChatToAll(getPlayer(id).getName(), chat);                        }						break;					case Packet.COMMAND_ENTITY_MOVE :						doEntityMovement(c, id);						break;					case Packet.COMMAND_ENTITY_ATTACK :						receiveAttack(c);						break;					case Packet.COMMAND_ENTITY_ADD :						receiveEntityAdd(c, id);                        resetPlayerReady();                        transmitAllPlayerReadys();						break;					case Packet.COMMAND_ENTITY_REMOVE :						receiveEntityDelete(c, id);                        resetPlayerReady();                        transmitAllPlayerReadys();						break;					case Packet.COMMAND_SENDING_GAME_SETTINGS :						gameSettings = (GameSettings)c.getObject(0);                        resetPlayerReady();                        transmitAllPlayerReadys();                        send(createSettingsPacket());						break;					}				}				// again!			}		}