       # Make sure we are the only one receiving command replies
       @socket.removeAllListeners('esl_command_reply')
       if cb?
-        @on 'esl_command_reply', (req,res) ->
+        @socket.on 'esl_command_reply', (req,res) ->
           cb(req,res)
 
       @socket.write "#{command}\n"

    @send "api #{command}", null, cb

  bgapi: (command,cb) ->
    @send "api #{command}", null, (req,res) ->
      if cb?
        r = res.header['Reply-Text']?.match /\+OK Job-UUID: (.+)$/
        cb r[1]

    res = new eslResponse socket
    socket.emit event, req, res
  # Get things started
  @emit 'esl_connect', new eslResponse socket if @emit?

class eslServer extends net.Server
  constructor: (requestListener) ->
