Quelqu'un a-t-il lu le protocole Hickson de 2010 projet-hixie-thewebsocketprotocol-76 WebSocket?HTML5: dernières WebSockets
Voici la source d'un fichier .htm:
<html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var socket = new WebSocket('ws://localhost:8181/websession');
socket.onopen = function() {
alert('handshake successfully established. May send data now...');
};
socket.onclose = function() {
alert('connection closed');
};
</script>
</head>
<body>
</body>
</html>
Si j'ai un port TCP en écoute sur 8181, c'est la demande que je reçois quand je charge le fichier .htm ci-dessus dans Chrome:
GET /websession HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:8181
Origin: null
[\n]
(où [\ n] est le caractère CRLF.)
Que dois-je retourner à cette poignée de main ouvre? projet-hixie-thewebsocketprotocol-76 spectacles:
HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Origin: http://example.com
Sec-WebSocket-Location: ws://example.com/demo
Sec-WebSocket-Protocol: sample
8jKS'y:G*Co,Wxa-
Cette réponse provoque socket.onclose
au feu bien.