public void run() {
		try {
			InputStream stream = socket.getInputStream();
			connected=true;
			while(connected){
				int byteCount = stream.available();
				if(byteCount>0){
					logger.debug(byteCount+" bytes are available for reading");
					byte[] oldByteBuffer = byteBuffer;
					//int oldByteBufferLength = oldByteBuffer==null?0:oldByteBuffer.length;
					int currentBufferLength = oldByteBuffer==null?0:oldByteBuffer.length;
					byteBuffer = new byte[currentBufferLength+byteCount];
					byte[] newBytes = new byte[byteCount];
					stream.read(newBytes, 0, byteCount);
					logger.debug(new String(newBytes, Charset.forName("UTF-8")));
					logger.debug("old byte buffer length: "+currentBufferLength);
					for (int i=0;i<currentBufferLength;i++){
						byteBuffer[i]=oldByteBuffer[i];
					}
					int newBufferLength=newBytes.length;
					logger.debug(new String(byteBuffer, Charset.forName("UTF-8")));
					for (int i=0;i<newBufferLength;i++){
						byteBuffer[currentBufferLength+i]=newBytes[i];
					}
					logger.debug(new String(byteBuffer, Charset.forName("UTF-8")));
					if(websocketImpl==null){
						handshake();
					}else{
						byte[] unusedBytes = websocketImpl.processFrame(byteBuffer);
						byteBuffer = unusedBytes;
					}
					//logger.debug(new String(byteBuffer));
				}
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		} catch (IOException ioe) {
			logger.debug("IOException on socket listen: " + ioe);
			ioe.printStackTrace();
		}
	}