6

When trying to connect to a custom socket server using SocketRocket I am getting the error:

Error Domain=SRWebSocketErrorDomain Code=2133 "Invalid Sec-WebSocket-Accept response" UserInfo=0x8f6af00 {NSLocalizedDescription=Invalid Sec-WebSocket-Accept response}

I have linked this back to the _checkHandshake method in _HTTPHeadersDidFinish. The _checkHandshake method is doing the following:

NSString *acceptHeader = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(httpMessage, CFSTR("Sec-WebSocket-Accept")));

I have found this question and have the latest version of socketrocket but doesn't seem to be working?

https://github.com/square/SocketRocket/issues/24

Please let me know how I get around this error (SocketRocket - Invalid Sec-WebSocket-Accept)

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
jodm
  • 2,607
  • 3
  • 25
  • 40
  • I'm having the same error – Agustin Haller Mar 07 '14 at 22:18
  • 3
    What websocket server are you using? I fixed this issue by forcing the connection between client and server to be through websockets. I'm using a SockJS server so i did that by adding "/websocket" to the url in order to "force" the communication to use websockets. Maybe that helps. – Agustin Haller Mar 09 '14 at 14:29

1 Answers1

10

I confirm that (using a SockJS server) by changing this:

    NSURL *url = [NSURL URLWithString:@"http://localhost:9090"];

to this:

    NSURL *url = [NSURL URLWithString:@"http://localhost:9090/websocket"];

the error was gone.

SudoPlz
  • 20,996
  • 12
  • 82
  • 123