   end
   def connection(:open_rcvd, %Frame.Open{}  = f, state) do
     Logger.info "Got an internal open frame"
-    :ok = AmqpOne.Transport.Socket.send(state.socket, encode_frame(f, 0))
+    :ok = AmqpOne.Transport.Socket.send(state.socket, encode_frame(0, f))
     %__MODULE__{state | state: :opened}
   end
   # channel must be zero for opening a connection

  end
  def connection(:open_sent, %Frame.Close{} = f, state) do
    Logger.info "Got an internal close frame: #{inspect f}"
    :ok = AmqpOne.Transport.Socket.send(state.socket, encode_frame(f, 0))
    %__MODULE__{state | state: :close_pipe}
  end
  def connection(:opened, %Frame.Close{} = f, state) do
    Logger.info "Got an internal close frame: #{inspect f}"
    :ok = AmqpOne.Transport.Socket.send(state.socket, encode_frame(f, 0))
    %__MODULE__{state | state: :close_sent}
  end
  # channel must be zero for closing a connection

  end
  def connection(:hdr_exch, %Frame.Open{} = f, state) do
    Logger.info "Client: sending open frame"
    :ok = AmqpOne.Transport.Socket.send(state.socket, encode_frame(0, f))
    %__MODULE__{state | state: :open_sent}
  end
  # channel must be zero for opening a connection
