   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))
+    :ok = AmqpOne.Transport.Socket.send(state.socket, encode_frame(0, f))
     %__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))
+    :ok = AmqpOne.Transport.Socket.send(state.socket, encode_frame(0, f))
     %__MODULE__{state | state: :close_sent}
   end
   # channel must be zero for closing a connection


  def send_open(state = %__MODULE__{}, role) do
    {:ok, hostname} = :inet.gethostname()
    frame = %Frame.Open{container_id: "AmqpOne"<>role, hostname: :hostname,
      max_frame_size: 1024*1024, channel_max: 10}
    new_state = connection(state.state, frame, state)
  end

  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(0, f))
    %__MODULE__{state | state: :opened}
  end
  # channel must be zero for opening a connection
