diff --git a/src/main/java/org/red5/server/net/rtmpe/RTMPEIoFilter.java b/src/main/java/org/red5/server/net/rtmpe/RTMPEIoFilter.java
index <HASH>..<HASH> 100644
--- a/src/main/java/org/red5/server/net/rtmpe/RTMPEIoFilter.java
+++ b/src/main/java/org/red5/server/net/rtmpe/RTMPEIoFilter.java
@@ -107,7 +107,7 @@ public class RTMPEIoFilter extends IoFilterAdapter {
 			IoBuffer message = (IoBuffer) obj;

 			if (rtmp.getState() == RTMP.STATE_HANDSHAKE) {

 				// ensure there are enough bytes to skip

-				if (message.limit() > Constants.HANDSHAKE_SIZE) {

+				if (message.limit() >= Constants.HANDSHAKE_SIZE) {

     				//skip the first 1536

     				byte[] handshakeReply = new byte[Constants.HANDSHAKE_SIZE];

     				message.get(handshakeReply);

@@ -118,6 +118,10 @@ public class RTMPEIoFilter extends IoFilterAdapter {
 					return;

 				}

 			}

+			// handle when C2 and message dont arrive at the same time

+			if (message.remaining() <= 0) {

+				return;

+			}

 			log.debug("Decrypting buffer: {}", message);

 			byte[] encrypted = new byte[message.remaining()];

 			message.get(encrypted);
Fix for RTMPE thanks to Ravi