             // get a random port
             let port = in_port_t(arc4random() % (49152 - 1024) + 1024)
             do {
-                try start(port)
+                try listenServer(port)
                 self.port = port
+                // backgrounding
+                NSNotificationCenter.defaultCenter().addObserver(
+                    self, selector: #selector(BRHTTPServer.suspend(_:)),
+                    name: UIApplicationWillResignActiveNotification, object: nil
+                )
+                NSNotificationCenter.defaultCenter().addObserver(
+                    self, selector: #selector(BRHTTPServer.suspend(_:)),
+                    name: UIApplicationDidEnterBackgroundNotification, object: nil)
+                // foregrounding
+                NSNotificationCenter.defaultCenter().addObserver(
+                    self, selector: #selector(BRHTTPServer.resume(_:)),
+                    name: UIApplicationWillEnterForegroundNotification, object: nil)
+                NSNotificationCenter.defaultCenter().addObserver(
+                    self, selector: #selector(BRHTTPServer.resume(_:)),
+                    name: UIApplicationDidBecomeActiveNotification, object: nil
+                )
                 return
             } catch {
                 continue

        
        fd = sfd
        acceptClients()
        print("[BRHTTPServer] Serving on \(port)")
    }
    
    func stop() {
        Darwin.shutdown(fd, SHUT_RDWR)
        close(fd)
        fd = -1

        throw BRHTTPServerError.SocketBindFailed
    }
    
    func listenServer(port: in_port_t, maxPendingConnections: Int32 = SOMAXCONN) throws {
        shutdownServer()
        
        let sfd = socket(AF_INET, SOCK_STREAM, 0)
        if sfd == -1 {
