我写了一个简单的https服务器,只响应" Hello world"。
该项目使用lib CocoaAsyncSocket
进行通信。
func socket(_ sock: GCDAsyncSocket, didAcceptNewSocket newSocket: GCDAsyncSocket) {
let session = Session(socket: newSocket)
session.delegate = self
sessions.append(session)
slog("https server receive new socket")
newSocket.enableBackgroundingOnSocket()
if let items = self.sslItems { // Enable https
newSocket.startTLS([kCFStreamSSLIsServer as String: kCFBooleanTrue, kCFStreamSSLCertificates as String: items, kCFStreamSSLValidatesCertificateChain as String : kCFBooleanFalse])
}
session.begin()
}
public func begin() {
socket.delegate = self
socket.readData(to: termData, withTimeout: -1, tag: SocketReadTag.readRequestHeader.rawValue)
slog("read request header")
}
我无法读取任何数据。为什么呢?