                 status-message.display "Starting remote atom server", 2000
 
         @server = net.createServer (socket) ->
-            console.log "[ratom] received connection from #{socket.remoteAddress}"
+            console.log "[ratom] received connection from #{socket.remote_address}"
             session = new Session(socket)
 
         port = atom.config.get "remote-atom.port"


    save: ->
        if not @session.alive
            console.log "[ratom] Error saving #{path.basename @tempfile} to #{@remoteAddress}"
            status-message.display "Error saving #{path.basename @tempfile} to #{@remoteAddress}", 2000
            return
        console.log "[ratom] saving #{path.basename @tempfile} to #{@remoteAddress}"
        status-message.display "Saving #{path.basename @tempfile} to #{@remoteAddress}", 2000
        @session.send "save"
        @session.send "token: #{@token}"
        data = fs.readFileSync(@tempfile)
        @session.send "data: " + Buffer.byteLength(data)
        @session.send data

    close: ->
        console.log "[ratom] closing #{path.basename @tempfile}"
        # try to close session
        @session.close()
        @subscriptions.dispose()

class Session
    should_parse_data: false
    readbytes: 0
    nconn: 0

    constructor: (socket) ->
        @socket = socket
        @send "Atom "+ atom.getVersion()
        @alive = true

        mkdirp.sync(dirname)
        @fd = fs.openSync(@tempfile, 'w')

    append: (line) ->
        if @readbytes < @datasize
            @readbytes += Buffer.byteLength(line)
            # remove trailing newline if necessary
            if @readbytes == @datasize + 1 and line.slice(-1) is "\n"
                @readbytes = @datasize
                line = line.slice(0, -1)
            fs.writeSync(@fd, line)
        if @readbytes >= @datasize
            fs.closeSync @fd
            @closed = true

    open: ->
        console.log "[ratom] opening #{@tempfile}"
        # register events
        atom.workspace.open(@tempfile, activatePane:true).then (editor) =>
