Telegraph: Basic unsecured server not working
When I use the demo that comes with Telegraph the server starts and works perfectly, however when I try to just test an unsecured server it doesn’t work.
The demo code that works:
server = Server(identity: identity, caCertificates: [caCertificate])
server.webSocketConfig.pingInterval = 10
server.webSocketDelegate = self
// Define the demo routes
server.route(.get, "hello/:name", serverHandleGreeting)
server.route(.get, "hello(/)", serverHandleGreeting)
server.route(.get, "secret/*") { .forbidden }
server.route(.get, "status") { (.ok, "Server is running") }
server.serveBundle(.main, "/")
// Start the server on localhost, we'll skip error handling for the demo
// Note: if you test in your browser, don't forget to type https://
try! server.start(onPort: 9000)
serverLog("Server is running at https://localhost:9000")
My test of a basic server that doesn’t work:
let server = Server()
server.route(.get, "status") { (.ok, "Server is running") }
try! server.start(onPort: 9000)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (10 by maintainers)
Interesting, it seems to be allowed on the actual device but not on the Simulator. See this StackOverflow post. I’m not really sure, I’d have to do some tests with this.
The unsecure server is working for me on iOS, without any problems.
@SmileAppDev are you retaining the
Serverinstance? InTelegraphDemoI’m assigning theServerinstance to a local variable so that it doesn’t get deallocated then thesetupServerfunction goes out of scope. If theServerinstance gets deallocated, it will automatically stop and close the sockets.If that isn’t the problem, could you send me your example? I’d be happy to have a look, maybe I can find the problem.