@Override
	public synchronized Object read() throws NetworkException
	{
		if(toAppStream != null) {
			throw new NetworkException(this, "Receiving is done via input stream. Do not call Connection.read."); 
		}
		
		if(toAppBuffer != null) {
			if(!toAppBuffer.isEmpty()) {
				// return data from buffer although the connection might be closed
				return toAppBuffer.removeFirst();
			}
		}
		
		if(!isConnected()) {
			throw new NetworkException("Connection is broken.");
		} else {
			// connection alive but no data available
			return null;
		}
	}