javascript - I can't connect to my websocket because its handshake Sec-WebSocket-Accept header value is incorrect -


i'm doing first test, trying use phpwebsocket.

i set handshake sec-websocket-accept header value following:

$accept=base64_encode(sha1($key."258eafa5-e914-47da-95ca-c5ab0dc85b11", true)); /* $key has $buffer value */ 

so run websocket php file (that creates connection), okay.

so run test html contains script try connect phpwebsocket i'm using, , in browser console error:

fc.js:43 websocket connection 'ws://localhost:8000/petstack/inc/server.php' failed: error during websocket handshake: incorrect 'sec-websocket-accept' header value 

but found error during websocket handshake: incorrect 'sec-websocket-accept' header value php, solved defining buffer limit, problem that?

i don't understand how define buffer limit, case it's problem, please explain me.

it wasn't me made phpwebsocket, i'm using it.

well, line of variable $upgrade in phpwebsocket file, sets headers.

                "http/1.1 101 web socket protocol handshake\r\n".                 "upgrade: websocket\r\n".                 "connection: upgrade\r\n".                 "websocket-origin:{$origin}\r\n".                 "sec-websocket-accept:".$accept."\r\n\r\n".                 "websocket-location: ws://{$host}{$resource}\r\n\r\n".                 chr(0); 

your handshake looks weird.

there not websocket-origin or websocket-locationheaders, , doing double break line between last two.

your response should more this:

http/1.1 101 switching protocols upgrade: websocket connection: upgrade sec-websocket-accept: hsmrc0smlyukagmm5oppg2hagwk= 

so try this:

"http/1.1 101 switching protocols\r\n". "upgrade: websocket\r\n". "connection: upgrade\r\n". "sec-websocket-accept: {$accept}\r\n\r\n" 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -