我正在使用Swift编写OS X的应用程序。我想使用SignalR-Client-Swift连接到Web套接字。服务器是使用.Net Core编写的。
var chatHubConnection: HubConnection?
var chatHubConnectionDelegate: ChatHubConnectionDelegate?
func applicationDidFinishLaunching(_ aNotification: Notification) {
chatHubConnectionDelegate = ChatHubConnectionDelegate(app: self)
chatHubConnection = HubConnectionBuilder(url: URL(string:"http://dev.cubepos.kz/hub/barcodegeneration")!)
.withLogging(minLogLevel: .debug)
.build()
chatHubConnection!.delegate = chatHubConnectionDelegate
chatHubConnection!.on(method: "NewMessage", callback: {args, typeConverter in
})
chatHubConnection!.start()
}
握手时连接失败
2018-08-27T14:19:12.752Z info: Registering client side hub method: 'NewMessage'
2018-08-27T14:19:12.758Z info: Starting hub connection
2018-08-27T14:19:12.758Z info: Starting connection
2018-08-27T14:19:12.758Z debug: Attempting to chage state from: 'initial' to: 'connecting'
2018-08-27T14:19:12.759Z debug: Changing state to: 'connecting' succeeded
2018-08-27T14:19:12.991Z debug: Negotiate completed with OK status code
2018-08-27T14:19:12.991Z debug: Negotiate response: {"connectionId":"DY0t3lztkscA15jZl-plHA","availableTransports":[{"transport":"WebSockets","transferFormats":["Text","Binary"]},{"transport":"ServerSentEvents","transferFormats":["Text"]},{"transport":"LongPolling","transferFormats":["Text","Binary"]}]}
2018-08-27T14:19:12.995Z info: Starting WebSocket transport
2018-08-27T14:19:13.159Z info: WebSocket open
2018-08-27T14:19:13.159Z info: Transport started
2018-08-27T14:19:13.159Z debug: Attempting to chage state from: 'connecting' to: 'connected'
2018-08-27T14:19:13.159Z debug: Changing state to: 'connected' succeeded
2018-08-27T14:19:13.159Z debug: Leaving startDispatchGroup (transportDidOpen(): 189)
2018-08-27T14:19:13.159Z debug: Invoking connectionDidOpen
2018-08-27T14:19:13.159Z info: Hub connection started
2018-08-27T14:19:13.160Z debug: Sending handshake request: {"protocol": "json", "version": 1}
2018-08-27T14:19:13.160Z debug: Sending data
2018-08-27T14:19:13.161Z info: WebSocket error. Error: ProtocolError(invalid extension)
2018-08-27T14:19:13.161Z info: Transport closed
2018-08-27T14:19:13.161Z debug: Attempting to chage state from: '(nil)' to: 'stopped'
2018-08-27T14:19:13.161Z debug: Changing state to: 'stopped' succeeded
2018-08-27T14:19:13.161Z debug: Previous state connected
2018-08-27T14:19:13.161Z debug: Invoking connectionDidClose (transportDidClose: 224)
2018-08-27T14:19:13.161Z info: HubConnection closing with error: Optional(ProtocolError(invalid extension))
2018-08-27T14:19:13.162Z info: Terminating 0 pending hub methods
2018-08-27T14:19:13.162Z info: WebSocket close. Clean: true, code: 1002, reason: Protocol error
2018-08-27T14:19:13.162Z debug: Transport already marked as closed due to an error - ignoring close
是我的错,还是应该在服务器端修复?