Error showing in console : WebSocket connection to 'ws://localhost/socket/php-socket.php/wss' failed: Error during WebSocket handshake: Unexpected response code: 200
PHP Code :
$newSocket = socket_accept($socketResource);
$clientSocketArray[] = $newSocket;
$header = socket_read($newSocket, 1024);
$chatHandler->doHandshake($header, $newSocket, HOST_NAME, PORT);
enter code here
Handshake function :
function doHandshake($received_header,$client_socket_resource, $host_name, $port) {
$headers = array();
$lines = preg_split("/\r\n/", $received_header);
foreach($lines as $line)
{
$line = chop($line);
if(preg_match('/\A(\S+): (.*)\z/', $line, $matches))
{
$headers[$matches[1]] = $matches[2];
}
}
$secKey = $headers['Sec-WebSocket-Key'];
$secAccept = base64_encode(pack('H*', sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
$buffer = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
"Upgrade: websocket\r\n" .
"Connection: Upgrade\r\n" .
"WebSocket-Origin: $host_name\r\n" .
"WebSocket-Location: ws://$host_name:$port/demo/shout.php\r\n".
"Sec-WebSocket-Accept:$secAccept\r\n\r\n";
socket_write($client_socket_resource,$buffer,strlen($buffer));
}
Javascript Code :
var websocket = new WebSocket("ws://localhost/socket/php-socket.php");
websocket.onopen = function(event) {
showMessage("<div class='chat-connection-ack'>Connection is established!</div>");
}
How we can insert header and footer in google docs with google docs api using PHP code
Writing a new and appending a file in PHP without erasing contents
How to combine 2 arrays with the condition that 2 and 5 values will be from the second array?
How to keep the ?error on url if page extension not included?
Cannot find the answer after my research, help me with mysql [duplicate]
I'm trying to make a login system with php and mysqlI verified that varchar(100) of password column in database is greater than 60 and went through the code several times, but still getting false from password_verify
so i want to make a little blog in php and mysql using a mvc arhitecturei want to add a function where you can report a comment(everything went well but i can't figure out how to remain on the same page after reporting)
im make a Publish Subscribe testim trying to using sleep(3) to delay for queue:worker until finish consume
I installed wamp64 on my computerPath is: c:/wamp64 I had some errors saying that php path variable were defined, so i deleted those