             console.log "[ratom] stop server"
         @server.listen port, 'localhost'
 
-
     deactivate: ->
-        @server.close()
+        if @online
+            @server.close()
+            @online = false

    configDefaults:{
        Port: 52698
    }
    activate: (state) ->
        @startserver()


    startserver: ->
        @server = net.createServer (socket) ->

            session.send("Atom "+atom.getVersion())

        port = atom.config.get "remote-atom.Port"
        @server.on 'listening', (e) =>
            @online = true
            console.log "[ratom] listening on port #{port}"
        @server.on 'error', (e) ->
            console.log "[ratom] unable to start server"
