Embed presentation
Download to read offline










![var mySocket= new WebSocket(‘ws://www.test.com’, [‘myProtocol’]);
mySocket.onopen = function() {};
mysocket.onclose = function() {};
mySocket.onmessage = functino() {};
mySocket.onerror = function() {};
mySocket.send() {};](https://crownmelresort.com/image.slidesharecdn.com/html5sockets-150319200609-conversion-gate01/75/Web-Sockets-HTML5-11-2048.jpg)




![if(preg_match("/Sec-WebSocket-Key: (.*)rn/",$hds,$matchs)){
$key = $matchs[1] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
$key = base64_encode(sha1($key, true));
$headers = "HTTP/1.1 101 Switching Protocolsrn".
"Upgrade: websocketrn".
"Connection: Upgradern".
"Sec-WebSocket-Accept: $key".
"rnrn";
socket_write($msgsock, $headers);
}](https://crownmelresort.com/image.slidesharecdn.com/html5sockets-150319200609-conversion-gate01/75/Web-Sockets-HTML5-16-2048.jpg)








The document discusses the integration of WebSocket in client-server communication, highlighting the differences between HTTP and WebSocket protocols. It includes sample code for establishing a WebSocket connection and handling events such as opening, closing, and messaging. Additionally, it covers the necessary headers for upgrading an HTTP connection to WebSocket.










![var mySocket= new WebSocket(‘ws://www.test.com’, [‘myProtocol’]);
mySocket.onopen = function() {};
mysocket.onclose = function() {};
mySocket.onmessage = functino() {};
mySocket.onerror = function() {};
mySocket.send() {};](https://crownmelresort.com/image.slidesharecdn.com/html5sockets-150319200609-conversion-gate01/75/Web-Sockets-HTML5-11-2048.jpg)




![if(preg_match("/Sec-WebSocket-Key: (.*)rn/",$hds,$matchs)){
$key = $matchs[1] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
$key = base64_encode(sha1($key, true));
$headers = "HTTP/1.1 101 Switching Protocolsrn".
"Upgrade: websocketrn".
"Connection: Upgradern".
"Sec-WebSocket-Accept: $key".
"rnrn";
socket_write($msgsock, $headers);
}](https://crownmelresort.com/image.slidesharecdn.com/html5sockets-150319200609-conversion-gate01/75/Web-Sockets-HTML5-16-2048.jpg)






