SwiftSocket
SwiftSocket copied to clipboard
how to start a websocket server?
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?
Yes, don't call testServer() on the main/UI thread. :)