@Override
	public void run() {
		try {
			OutputStream responseStream = client.socket().getOutputStream();
		
			while(running){
					lock.lock();
	
					if(responseQueue.isEmpty()){
						//System.err.println("sender: empty queue waiting!");
						has_data.await();
						
						//System.err.println("sender: got data");
					}
					
					while(responseQueue.size()>0){
						//System.err.println(tag+" sending response!");
						Response currentResponse = responseQueue.poll();
						//System.err.println(tag+" sending header!");
						responseStream.write(currentResponse.getHeader().getBytes());
						int len = 0;
						int to_send = 0;
						int left = 0;
						if(currentResponse.hasEntity()){
							//System.err.println("sender sending data!");
							while(len<currentResponse.getContent_length()){
								left 	= currentResponse.getContent_length()-len;
								//System.err.println(tag+" reading next chunk!");
								to_send = currentResponse.getEntity(sendBufferArray, len,left);
								len     += to_send;
								//System.err.println(tag+" sending "+to_send+" bytes!");
								responseStream.write(sendBufferArray, 0, to_send);
								//System.err.println(tag+" finished "+len+" bytes! "+left+" bytes left!");
							}
							//System.err.println(" done sending entity! ("+len+" bytes)");
						}
						running = currentResponse.isKeep_alive();
						
						parent.setKeepAlive(running);
					}

					lock.unlock();
			}
		} catch (InterruptedException e) {
			running = false;
		} catch (IOException e) {
			running = false;
			parent.setKeepAlive(false);
		} finally{
			try {
				socketLock.lock();
				exchangeFinshed.await();
				client.close();
				socketLock.unlock();
			}
			catch (InterruptedException e) {}
			catch (IOException e) {}
		}
	}