 
     constructor: (socket) ->
         @socket = socket
-        @remoteAddress = socket.remoteAddress
+        @online = true
         socket.on "readable", =>
             chunk = socket.read()
             @parse_chunk(chunk)
+        socket.on "close", =>
+            @online = false
 
     make_tempfile: ()->
-        @tempfile = path.join(os.tmpdir(), randomstring(10), @token)
+        @tempfile = path.join(os.tmpdir(), randomstring(10), @basename)
         console.log "[ratom] create #{@tempfile}"
         dirname = path.dirname(@tempfile)
         mkdirp.sync(dirname)

        @socket.write cmd+"\n"

    save: ->
        console.log "[ratom] saving #{path.basename @tempfile} to #{@remoteAddress}"
        message.display "Saving #{path.basename @tempfile} to #{@remoteAddress}", 2000
        @send "save"

                switch m[1]
                    when "token"
                        @token = m[2]
                    when "data"
                        @datasize = parseInt(m[2],10)
                        @should_parse_data = true
                    when "display-name"
                        @displayname = m[2]
                        @remoteAddress = @displayname.split(":")[0]
                        @basename = @displayname.split(":")[1]
                        @make_tempfile()


    open_in_atom: ->
