I'm trying to build a websocket server on Delphi6 using the draft hixie-76 and i have a problem with the handshake.
The md5 fingerprint i get with the three parts does not seem to be correct when i try it, but when i use the same algorythm with the exemple given in the protocole spec i get the good md5 response...
I'm processing like this, transform the number found in key1 divided by the number of spaces in a 32 bits word, same with key2 and finally adding the last 8 bytes (key3) to get a 128 bits string which i use as md5 entry.
using 155712099, 173347027 for key1 and key2 and 'Tm[K T2u' for key3, i get the correct md5 fingerprint and so i don't understand why this algo won't give a correct fingerprint to the client
here is an exemple of what i receive :
GET / HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:8018
Origin: null
Sec-WebSocket-Key1: 4 102(2 6U 2 3 18
Sec-WebSocket-Key2: 69V86`6t)e 0 2 42
M]Rzÿõ&
and the handshake i give in response
HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Origin: null
Sec-WebSocket-Location: ws://localhost:8018/
µ&Mq˜8èõÙZÙ,hœi
Maybye there's another probleme with my response but it reall seems that i have a problem with my md5 fingerprint.
Does anyone see where my mistake is??
Thanks in advance for your help
Update
I have seen this unit but unless i'm very bad at reading, the handshake part of this class does not calculate any md5 sum, i think it uses an older version of the protocol and not the current (76)
When i look at the following code i see that the answer is written without any md5 response.
` try // Read request headers HandshakeRequest := TWebSocketRequest.Create(ServerConnection);
// Send response headers
ServerConnection.WriteLn('HTTP/1.1 101 Web Socket Protocol Handshake');
ServerConnection.WriteLn('Upgrade: WebSocket');
ServerConnection.WriteLn('Connection: Upgrade');
ServerConnection.WriteLn('WebSocket-Origin: ' + HandshakeRequest.Origin);
ServerConnection.WriteLn('WebSocket-Location: ws://' + HandshakeRequest.Host + '/');
// End handshake
ServerConnection.WriteLn;
ServerConnection.WriteLn;
HandshakeResponseSent := True;
except on E: TWebSocketHandshakeException do begin // Close the connection if the handshake failed ServerConnection.Disconnect; end;`
Thanks again
Update 2011 04 14
I have finally found where the problem was...
i was building my response like that :
resp := [...] +'Sec-WebSocket-Origin: '+ origin + #13#10 +
so there was 3 0x0D 0x0A instead of 2 before the md5 fingerprint ...
#13#10#13#10 +
md5response;
Since i cannot answer my own question i won't be able to mark it solve but it is! :)