 
   return defered.promise
 
-###
-# A promise returning function that send a request to the given route using sockets and resolves
-# the returned promise with a response object of the following form: ()
-#   response =
-#    status: <200 if all work, else 500>
-#    body: <the received data from the socket>
-#    timestamp: <the time the response was recieved>
-###
-sendMLLPSocketRequest = (ctx, route, options) ->
-
-  endChar = `String.fromCharCode(034)`
-  defered = Q.defer()
-  requestBody = ctx.body
-  client = new net.Socket()
-  response = {}
-
-  client.connect options.port, options.hostname, ->
-    logger.info "Opened mllp connection to #{options.hostname}:#{options.port}"
-
-  client.on 'connect', ()->
-    client.write requestBody
-
-  bufs = []
-  client.on 'data', (chunk) ->
-    bufs.push chunk
-    n = chunk.toString().indexOf(endChar)
-    if n > -1
-      logger.info 'Received response end character'
-      response.body = Buffer.concat bufs
-      response.status = status.OK
-      response.timestamp = new Date()
-      if not defered.promise.isRejected()
-        defered.resolve response
-        client.end()
-
-
-  client.on 'error', (err) -> defered.reject err
-
-  client.on 'end', ->
-    logger.info "Closed mllp connection to #{options.hostname}:#{options.port}"
-
-  return defered.promise
-
-
 getDestinationPath = (route, requestPath) ->
   if route.path
     route.path

    options.ca = route.cert

  client = method.connect options, ->
    logger.info "Opened tcp connection to #{options.host}:#{options.port}"
    client.end requestBody

  bufs = []
  client.on 'data', (chunk) ->
    bufs.push chunk

  client.on 'error', (err) -> defered.reject err

  client.on 'end', ->
    if route.secured and not client.authorized
      return defered.reject new Error 'Client authorization failed'
    response.body = Buffer.concat bufs

#    status: <200 if all work, else 500>
#    body: <the received data from the socket>
#    timestamp: <the time the response was recieved>
#
# Supports both normal and MLLP sockets
###
sendSocketRequest = (ctx, route, options) ->
  mllpEndChar = String.fromCharCode(0o034)

  defered = Q.defer()
  requestBody = ctx.body
  response = {}
