httpswift / swifter

Tiny http server engine written in Swift programming language.
BSD 3-Clause "New" or "Revised" License
3.9k stars 538 forks source link

Server doesn't answer even when state is "HttpServerIOState.running" #297

Open eric-22 opened 6 years ago

eric-22 commented 6 years ago

Hello,

It happens quite frequently that I do not receive an answer from the Swifter server until the timeout of the client. And if there is no timeout on the client, the request runs indefinitely. The connection is open but the server never returns an answer or closes it.

This happens more frequently if I start the Swifter server right after a change of connection/passover to plane mode. The combination airplane mode + wifi on but not connected to a network is the one where the problem appears most frequently. Without understanding the connection...

Here are snippets of code I use :

instance.webServer = HttpServer()
instance.webServer!["/:path"] = shareFilesFromDirectory((Utility.containerPath()?.path)! + "/\(ApplicationIdentifier)")

func start() -> Bool {
        do {
            try instance.webServer!.start(PORT, forceIPv4: false, priority: .default)
            return true
        } catch {
            return false
        }
    }

When the problem appears, thestart function does not trigger exceptions and the state is still equal to "running".

yoyoFan commented 6 years ago

Is it related to the mobile phone? What I have encountered is that some mobile phones can respond immediately. Some phones just don't respond. Don't know what the problem is? Run the Demo directly.