如何增加 websocket 的帧长度?
How do I increase the frame length of a websocket?
当我通过 WebSocket 连接向 vapor swift 服务器发送大量 JSON 时,连接关闭并出现以下错误:
invalidFrameLength
错误描述为:
The operation couldn’t be completed. (NIOWebSocket.NIOWebSocketError error 0.)
我的 configure.swift 看起来像这样:
let webSocketServer: NIOWebSocketServer = NIOWebSocketServer.default()
try sockets(webSocketServer)
services.register(webSocketServer, as: WebSocketServer.self)
和套接字函数:
public func sockets(_ webSocketServer: NIOWebSocketServer) throws {
webSocketServer.get("example") { (webSocket: WebSocket, request: Request) in
}
}
我如何增加服务器端的帧长度才能发送大 JSON?
现在可以使用 Vapor 4:
app.webSocket("route", maxFrameSize: .init(integerLiteral: 1 << 24)) { (request: Request, webSocket: WebSocket) in
// code ...
}
app.webSocket("route", maxFrameSize: 16_777_216) { (request: Request, webSocket: WebSocket) in
// code ...
}
当我通过 WebSocket 连接向 vapor swift 服务器发送大量 JSON 时,连接关闭并出现以下错误:
invalidFrameLength
错误描述为:
The operation couldn’t be completed. (NIOWebSocket.NIOWebSocketError error 0.)
我的 configure.swift 看起来像这样:
let webSocketServer: NIOWebSocketServer = NIOWebSocketServer.default()
try sockets(webSocketServer)
services.register(webSocketServer, as: WebSocketServer.self)
和套接字函数:
public func sockets(_ webSocketServer: NIOWebSocketServer) throws {
webSocketServer.get("example") { (webSocket: WebSocket, request: Request) in
}
}
我如何增加服务器端的帧长度才能发送大 JSON?
现在可以使用 Vapor 4:
app.webSocket("route", maxFrameSize: .init(integerLiteral: 1 << 24)) { (request: Request, webSocket: WebSocket) in
// code ...
}
app.webSocket("route", maxFrameSize: 16_777_216) { (request: Request, webSocket: WebSocket) in
// code ...
}