         end
     end
   end
+
+  defp check_min_protocol!(protocol) when protocol < @min_protocol do
+    raise Error, """
+    the minimum supported protocol is #{@min_protocol}, the server is using #{protocol}
+    """
+  end
+
+  defp check_min_protocol!(_) do
+    :ok
+  end
 end

  defp negotiate_protocol(%{socket: socket, opts: opts} = s) do
    case :gen_tcp.recv(socket, 2, opts[:timeout] || @timeout) do
      {:ok, <<version :: short>>} ->
        {:ok, %{s | protocol_version: version}}
      {:error, reason} ->
        {:tcp_error, reason}


  @typep state :: Map.t

  @min_protocol 28
  @protocol 30

  @timeout 5000
