swiftNIO websocket server doesn't work correctly on the backgound of UI

I used SwiftNIO as a websocket server according to this link, and it works fine when I execute it on the main thread but when I run it on the background of main thread like this

       DispatchQueue.global(qos: .userInitiated).async {
            let server = SecondServer()
            server.run()
        } 

it doesn't receive any message from client. this is my server code:

Can anybody help me to solve my problem? Thanks.

Running in the main thread or a background thread shouldn't affect this code at all. Are you still seeing the printed "Server started and listening on" message in your logs?

Probably your server constant gets deallocated right after calling server.run() maybe you need to keep a global reference somewhere

swiftNIO websocket server doesn't work correctly on the backgound of UI
 
 
Q