         @send ""
 
     close: ->
+        @online = false
         @send "close"
         @send ""
         @socket.end()


    constructor: (socket) ->
        @socket = socket
        @remoteAddress = socket.remoteAddress
        socket.on "readable", =>
            chunk = socket.read()
            @parse_chunk(chunk)

    make_tempfile: ()->
        @tempfile = path.join(os.tmpdir(), randomstring(10), @token)
        console.log "[ratom] create #{@tempfile}"
        dirname = path.dirname(@tempfile)
        mkdirp.sync(dirname)

        @socket.write cmd+"\n"

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