SwiftSocket icon indicating copy to clipboard operation
SwiftSocket copied to clipboard

how to start a websocket server?

Open spencercap opened this issue 6 years ago • 1 comments

hey, im new to this environment and confused as to how to start a websocket server on an ios device then connect to it from a browser client. i have tried running testServer()

func testServer() {
    let server = TCPServer(address: "127.0.0.1", port: 8080)
    switch server.listen() {
      case .success:
        while true {
            if var client = server.accept() {
                echoService(client: client)
            } else {
                print("accept error")
            }
        }
      case .failure(let error):
        print(error)
    }
}

but the ios app freezes on my devices without any errors in the console.

thoughts?

spencercap avatar Aug 24 '18 06:08 spencercap

Yes, don't call testServer() on the main/UI thread. :)

CodeReaper avatar Aug 19 '19 08:08 CodeReaper