WebSocket连接的ws: / / 127.0.0.1:8888 /失败:错误WebSocket握手期间:响应必须不包括“Sec-WebSocket-Protocol”头

WebSocket connection to 'ws://127.0.0.1:8888/' failed: Error during WebSocket handshake: Response must not include 'Sec-WebSocket-Protocol' header if not present in request: chat

 

这个,在后端握手时设置一下请求头:

    $response = "HTTP/1.1 101 Switching Protocols\r\n";
    $response .= "Upgrade: websocket\r\n";
    $response .= "Connection: Upgrade\r\n";
    $response .= "Sec-WebSocket-Accept: $new_key\r\n";
    $response .= "Sec-WebSocket-Protocol: chat\r\n\r\n";

前端设置的值:

socket = new WebSocket('ws://127.0.0.1:8888',"chat");

 

websocket官方文档: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

http://www.rfcreader.com/#rfc6455

你可能感兴趣的:(php)