           {:noreply, port} = res
           state = %{state | sock: port}
         end
-        connect(self(), connect_json)
+        connect(self(), to_send)
         {:noreply, %{state | state: :connected}}
       {:error, why} -> nats_err(state, why)
     end

  
  @start_state %{state: :want_info,
                 sock: nil,
                 opts: %{tls_required: false, auth: nil,
                         verbose: false,
                         timeout: @default_timeout,
                         host: @default_host, port: @default_port,

    IO.puts ("received nats_err: #{inspect(what)}")
    {:noreply, %{state | state: :error}}
  end
  defp check_auth(json_received = %{}, json_to_send = %{}, auth_opts = %{}) do
    server_want_auth = json_received["auth_required"] || false
    we_want_auth = Enum.count(auth_opts) != 0
    case {server_want_auth, we_want_auth} do
      {x, x} -> {:ok, Map.merge(json_to_send, auth_opts)}
      _ -> {:error, "client and server disagree on authorization"}
    end
  end
  defp nats_info(state = %{state: :want_info}, json) do
    # IO.puts "NATS: received INFO: #{inspect(json)}"
