         fun.(conn, stanza)
       {:tcp, ^socket, data} ->
         :ok = activate({:gen_tcp, 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
       {:tcp_closed, ^socket} ->
         {:error, :closed}
       {:tcp_error, ^socket, reason} ->

    receive do
      {:xmlstreamelement, stanza} ->
        fun.(conn, stanza)
      {:ssl, ^socket, data} ->
        :ok = activate({:ssl, socket})
        {:ok, conn, stanza} = parse_data(conn, data)
        fun.(conn, stanza)
      {: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)
  end

  defp whitespace_only?(data), do: Regex.match?(~r/^\s+$/, data)

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