package server;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.concurrent.Semaphore;

public class ServerInputThread implements Runnable {

	public int player;
	int receivePort;
	Semaphore semNewMessage;

	public ServerInputThread(int port, int player, Semaphore semNewMessage) {
		receivePort = port;
		this.player = player;
		this.semNewMessage = semNewMessage;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		DatagramSocket serverSocket = null;
		DatagramPacket receivePacket = null;
		byte[] receivedData = new byte[1024];

		try {
			serverSocket = new DatagramSocket(receivePort);
			serverSocket.setReuseAddress(true);
			receivePacket = new DatagramPacket(receivedData,
					receivedData.length);
			serverSocket.receive(receivePacket);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			serverSocket.close();
			e.printStackTrace();
		}

		while (Server.getInGame()) {
			receivedData = new byte[1024];
			
			System.out.println(player +" Pressed: " +new String(receivePacket.getData()));
			semNewMessage.release();
			synchronized (GameEngine.command){
				GameEngine.command = new String(receivePacket.getData()).trim()+","+player;
			}
			try {
				receivePacket = new DatagramPacket(receivedData,
						receivedData.length);
				serverSocket.receive(receivePacket);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
		}
		serverSocket.close();
	}
}

@@ -270,24 +270,150 @@
 Message;%0D%0A%0D%0A
+%09/**%0D%0A%09 * assigns specified paramters to field variables%0D%0A%09 * @param port%0D%0A%09 * @param player%0D%0A%09 * @param semNewMessage%0D%0A%09 */%0D%0A
 %09public Serv
@@ -581,16 +581,244 @@
 erride%0D%0A
+%09/**%0D%0A%09 * Runs the Servers Input Thread by initializing sockets and packets alike.%0D%0A%09 * Checks if the players are able to get in game. If yes, then the communication%0D%0A%09 * link is established and packets are sent through.%0D%0A%09 */%0D%0A
 %09public 

Update ServerInputThread.java