 
 
   whichServer: (roomid, callback) ->
-    self = @
     options =
       host: 'turntable.fm'
       port: 80
       path: "/api/room.which_chatserver?roomid=#{roomid}"
-    http.get options, (res) ->
+    http.get options, (res) =>
       dataStr = ''
-      res.on 'data', (chunk) ->
+      res.on 'data', (chunk) =>
         dataStr += chunk.toString()
-      res.on 'end', ->
+      res.on 'end', =>
         try
           data = JSON.parse dataStr
         catch err
           data = []
         if data[0]
           [host, port] = data[1].chatserver
-          callback.call(self, host, port)
+          callback.call(@, host, port)
         else
-          self.log "Failed to determine which server to use: #{dataStr}"
+          @log "Failed to determine which server to use: #{dataStr}"
 
 
   setTmpSong: (data) ->

        allInfos = arguments[1]
        callback = arguments[2]

    getGraph = ->
      self.directoryGraph (directoryGraphData) ->
        if not directoryGraphData.success
          return callback directoryGraphData
        for graphObj in directoryGraphData.rooms



  listen: (port, address) ->
    http.createServer((req, res) =>
      dataStr = ''
      req.on 'data', (chunk) =>
        dataStr += chunk.toString()
      req.on 'end', =>
        data = querystring.parse(dataStr)
        req._POST = data
        @emit 'httpRequest', req, res
    ).listen(port, address)


  tcpListen: (port, address) ->
    net.createServer((socket) =>
      socket.on 'connect', =>
        @emit 'tcpConnect', socket
      socket.on 'data', (data) =>
        msg = data.toString()
        if msg[msg.length - 1] == '\n'
          @emit 'tcpMessage', socket, msg.substr(0, msg.length-1)
      socket.on 'end', ->
        @emit 'tcpEnd', socket
    ).listen(port, address)


