diff --git a/lib/zmachine/connection.rb b/lib/zmachine/connection.rb
index <HASH>..<HASH> 100644
--- a/lib/zmachine/connection.rb
+++ b/lib/zmachine/connection.rb
@@ -173,8 +173,14 @@ module ZMachine
     def readable!
       ZMachine.logger.debug("zmachine:connection:#{__method__}", connection: self) if ZMachine.debug
       mark_active!
-      data = @channel.read_inbound_data
-      receive_data(data) if data
+      loop do
+        data = @channel.read_inbound_data
+        if data
+          receive_data(data)
+        else
+          break
+        end
+      end
       nil
     end
 
diff --git a/lib/zmachine/tcp_msg_channel.rb b/lib/zmachine/tcp_msg_channel.rb
index <HASH>..<HASH> 100644
--- a/lib/zmachine/tcp_msg_channel.rb
+++ b/lib/zmachine/tcp_msg_channel.rb
@@ -80,14 +80,7 @@ module ZMachine
         end
       end
 
-      # clear buffer
-      if @buffer.remaining
-        bytes = java.util.Arrays.copyOfRange(@buffer.array, @buffer.position, @buffer.position+@buffer.remaining)
-        @buffer.clear
-        @buffer.put(bytes)
-      else
-        @buffer.clear
-      end
+      @buffer.compact
 
       data
     end
allow for more than one receive_data per read_inbound_data