     setTimeout retry, milliseconds
 
   send : (message) ->
+    if @socket == null
+      throw new Error("not connected so cannot send #{message}")
     message.send(@socket)
 
   send_with_reply : (message) ->
     promise = new Promise (resolve, reject) =>
       @_pending_replies[message.msgid()] = [resolve, reject]
-      message.send(@socket)
+      @send(message)
 
     promise.then(
       (message) ->

    @buffers = []

  @assemble : (header_json, metadata_json, content_json) ->
    new Message(JSON.parse(header_json), JSON.parse(metadata_json), JSON.parse(content_json))

  @create_header : (msgtype, options) ->
    header = {

    new Message(header, {}, content)

  send : (socket) ->
    try
      header_json = JSON.stringify(@header)
      metadata_json = JSON.stringify(@metadata)
      content_json = JSON.stringify(@content)
      socket.send(header_json)
      socket.send(metadata_json)
      socket.send(content_json)
    catch e
      logger.error("Error sending ", @, e)
      throw e

  complete : ->
    if @header? and @metadata? and @content?
