Why should we use a socket ?
HTTP ?
The client side
The server side
Trying to join the parts together
Agenda
FRONT-END
x
BACK-END
var mySocket= new WebSocket(‘ws://www.test.com’, [‘myProtocol’]);
mySocket.onopen = function() {};
mysocket.onclose = function() {};
mySocket.onmessage = functino() {};
mySocket.onerror = function() {};
mySocket.send() {};
GET /hello-web-socket HTTP/1.1
Host: marabesi.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key:
x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: myProtocol
Sec-WebSocket-Version: 13
Origin: http://google.com
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept:
HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: myProtocol
Talk is cheap,
show me the code.
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);
}
Matheus Marabesi
github.com/marabesi
twitter.com/MatheusMarabesi

Web Sockets - HTML5