       line = (s) =>
         [type, data] = JSON.parse s
         if @handlers.hasOwnProperty type
-          @handlers[type] data
+          if data.callback?
+            @handlers[type] data, (result) =>
+              @msg data.callback, result
+          else
+            @handlers[type] data
         else if @callbacks.hasOwnProperty type
           @callbacks[type] data
           delete @callbacks[type]

  callbacks: {}
  id: 0

  listen: (f) ->
    return f?(@port) if @port?
    @server = net.createServer (c) =>

      c.on 'end', =>
        @client = null
        @emitter.emit 'disconnected'
        @loading?.reset()
      # Data will be split into chunks, so we have to buffer it before parsing.
      buffer = ['']
      c.on 'data', (data) =>
