@Override
	public void run() {
		
		//create player
		if(!PC.player1Connected){
			PC.player1Connected = true;
			PC.state.player.setPos(new Vector(2*PistolCaveGame.TILE_SIZE, 2*PistolCaveGame.TILE_SIZE));
			PC.state.player.setDirection(2);
			PC.state.firstPlayer = true;
		}
		
		else if(!PC.player2Connected){
			PC.player2Connected = true;
			PC.state.player2.setPos(new Vector(2*PistolCaveGame.TILE_SIZE, 2*PistolCaveGame.TILE_SIZE));
			PC.state.player2.setDirection(2);
			PC.state.secondPlayer= true;
		}
		
		else{
			//handle too many connections
		}
	
			try {
				estConn();
			} catch (IOException e) {
				e.printStackTrace();
				System.out.print("Error connecting to client");
				}
			
			System.out.println("Connected to " + hostName);		
			
		//open object streams
	    try {
	      socketOut = new ObjectOutputStream(socket.getOutputStream());
	      socketIn = new ObjectInputStream(socket.getInputStream());
	    }
	    catch(IOException e){
			e.printStackTrace();
			System.out.println("Error opening streams");
	    }
	    
	    try {
			socketOut.writeObject(PC.state);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	    
	    while(!quit){
	    	//loop to write game state to client and get user input from client
		    	
			try {
				socketOut.reset();
				socketOut.writeObject(PC.state);
			} catch (IOException e) {
				e.printStackTrace();
				System.out.println("Error Writing game state to client.");
			}
			
			try {
				playerState = (clientState) socketIn.readObject();
			} catch (ClassNotFoundException | IOException e) {
				System.out.println("Error reading clientState.");
				e.printStackTrace();
			}
				
			PC.update(playerState);
			try {
				Thread.sleep(2);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }
	    
	}