diff --git a/src/main/java/com/github/shyiko/mysql/binlog/network/protocol/PacketChannel.java b/src/main/java/com/github/shyiko/mysql/binlog/network/protocol/PacketChannel.java index 0ada6542..fa1770ec 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/network/protocol/PacketChannel.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/network/protocol/PacketChannel.java @@ -63,12 +63,14 @@ public byte[] read() throws IOException { public void write(Command command, int packetNumber) throws IOException { byte[] body = command.toByteArray(); - outputStream.writeInteger(body.length, 3); // packet length - outputStream.writeInteger(packetNumber, 1); - outputStream.write(body, 0, body.length); + ByteArrayOutputStream wtf = new ByteArrayOutputStream(); + wtf.writeInteger(body.length, 3); // packet length + wtf.writeInteger(packetNumber, 1); + wtf.write(body, 0, body.length); // though it has no effect in case of default (underlying) output stream (SocketOutputStream), // it may be necessary in case of non-default one - outputStream.flush(); + wtf.flush(); + socket.getOutputStream().write(wtf.toByteArray()); } public void write(Command command) throws IOException {