Can't connect to websocket from macOS game template

Hi, I'm trying to setup a simple websocket connection from the project game template. Using NWWebSocket 0.5.4 or urlSession.webSocketTask on the client and Vapor on the server.

Haven't been able to connect since macOS ~14-15 with the same Xcode settings.

I can send HTTP routes but the websocket itself does not connect. The closest I've got is connect but then immediate disconnect. I know the websocket works with CLI.

Have plist allowing arbitrary loads and local networking. Also App Sandbox with network boxes checked in Debug mode.

The error I get is:

Error receiving: Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server." UserInfo={NSErrorFailingURLStringKey=http://localhost:8090/echo, NSErrorFailingURLKey=http://localhost:8090/echo, _NSURLErrorWebSocketHandshakeFailureReasonKey=5, NSLocalizedDescription=There was a bad response from the server.}
Failed to send message: Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server."

Thanks.

Answered by DTS Engineer in 835173022

Error -1011 is NSURLErrorBadServerResponse, which strongly suggests that the server sent a response that the client didn’t like. I recommend that you use a packet trace to see what’s happening on the ‘wire’.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Error -1011 is NSURLErrorBadServerResponse, which strongly suggests that the server sent a response that the client didn’t like. I recommend that you use a packet trace to see what’s happening on the ‘wire’.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi, please see packet trace

tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on lo0, link-type NULL (BSD loopback), snapshot length 524288 bytes

10:50:57.337495 IP6 ::1.59392 > ::1.8090: Flags [S], seq 2780678002, win 65535, options [mss 16324,nop,wscale 6,nop,nop,TS val 1305296417 ecr 0,sackOK,eol], length 0

10:50:57.337518 IP6 ::1.8090 > ::1.59392: Flags [R.], seq 0, ack 2780678003, win 0, length 0

10:50:57.337801 IP 127.0.0.1.59393 > 127.0.0.1.8090: Flags [S], seq 3048341153, win 65535, options [mss 16344,nop,wscale 6,nop,nop,TS val 265350921 ecr 0,sackOK,eol], length 0

10:50:57.337850 IP 127.0.0.1.8090 > 127.0.0.1.59393: Flags [S.], seq 81909635, ack 3048341154, win 65535, options [mss 16344,nop,wscale 6,nop,nop,TS val 2129330007 ecr 265350921,sackOK,eol], length 0

10:50:57.337858 IP 127.0.0.1.59393 > 127.0.0.1.8090: Flags [.], ack 1, win 6380, options [nop,nop,TS val 265350921 ecr 2129330007], length 0

10:50:57.337865 IP 127.0.0.1.8090 > 127.0.0.1.59393: Flags [.], ack 1, win 6380, options [nop,nop,TS val 2129330007 ecr 265350921], length 0

10:50:57.338107 IP 127.0.0.1.59393 > 127.0.0.1.8090: Flags [P.], seq 1:376, ack 1, win 6380, options [nop,nop,TS val 265350921 ecr 2129330007], length 375

10:50:57.338119 IP 127.0.0.1.8090 > 127.0.0.1.59393: Flags [.], ack 376, win 6375, options [nop,nop,TS val 2129330007 ecr 265350921], length 0

10:50:57.340508 IP 127.0.0.1.8090 > 127.0.0.1.59393: Flags [P.], seq 1:167, ack 376, win 6375, options [nop,nop,TS val 2129330009 ecr 265350921], length 166

10:50:57.340533 IP 127.0.0.1.59393 > 127.0.0.1.8090: Flags [.], ack 167, win 6378, options [nop,nop,TS val 265350923 ecr 2129330009], length 0

10:50:57.341578 IP 127.0.0.1.59393 > 127.0.0.1.8090: Flags [F.], seq 376, ack 167, win 6378, options [nop,nop,TS val 265350925 ecr 2129330009], length 0

10:50:57.341605 IP 127.0.0.1.8090 > 127.0.0.1.59393: Flags [.], ack 377, win 6375, options [nop,nop,TS val 2129330011 ecr 265350925], length 0

10:50:57.341644 IP 127.0.0.1.8090 > 127.0.0.1.59393: Flags [F.], seq 167, ack 377, win 6375, options [nop,nop,TS val 2129330011 ecr 265350925], length 0

10:50:57.341672 IP 127.0.0.1.59393 > 127.0.0.1.8090: Flags [.], ack 168, win 6378, options [nop,nop,TS val 265350925 ecr 2129330011], length 0

Accepted Answer

problem solved, using an older version of vapor server, not forward compatible. Thanks for your help.

Can't connect to websocket from macOS game template
 
 
Q