     receive do
       {:xmlstreamelement, stanza} ->
         fun.(conn, stanza)
+      {:ssl, ^socket, " "} ->
+        :ok = activate({:ssl, socket})
+        conn
       {:ssl, ^socket, data} ->
         :ok = activate({:ssl, socket})
-        {:ok, conn, stanza} = parse_data(conn, data)
-        fun.(conn, stanza)
+
+        if whitespace_only?(data) do
+          conn
+        else
+          {:ok, conn, stanza} = parse_data(conn, data)
+          fun.(conn, stanza)
+        end
       {:ssl_closed, ^socket} ->
         {:error, :closed}
       {:ssl_error, ^socket, reason} ->


  defp handle_data(data, %{socket: socket} = conn) do
    :ok = activate(socket)
    {:ok, _conn, _stanza} = parse_data(conn, data, false)
  end

  defp activate({:gen_tcp, socket}) do
    case :inet.setopts(socket, [active: :once]) do

    %{conn | parser: parser}
  end

  defp parse_data(%Conn{jid: jid, parser: parser} = conn, data) do
    Logger.debug fn -> "[#{jid}][INCOMING] #{inspect data}" end

    parser = :fxml_stream.parse(parser, data)
