Skip to content
Advertisement

php server socket & webSocket HTML5 client

what i’m trying is connect the client [webSocket] with PHP server socket my server socket will accept the socket from client, and fetch the Request headers,

after receiving the Request, i sent back handshake [response] But the status for webSocket [client] is pending and never get the response

JS code:

JavaScript

and my PHP server Socket:

JavaScript

handshake function:

JavaScript

After sending the response, the client still in pending status, and the connection not openned.

Thank you.

The Request From Client:

JavaScript

what i’m trying is sending back the response:

JavaScript

UPDATE:

  • I fixed the Sec-WebSocket-Accept key by using sha1(…, binary = true) before base64.

  • End my Response i added rn to end the header response.

Now i’m getting error: webSocket connection http://host:port failed.

Advertisement

Answer

It’s done, the problem was Sec-WebSocket-Accept key, it needed to be trim(key)

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement