WebSocket et Decodage message
Bonjour,
je travaille sur un serveur web en C#, avec page htm avec JavaScript.
Je cherche à écrire en c# un serveur web (je sais faire) mais qui fait aussi websocket ,
pour cela je voudrais retrouver le message 'test echo' que j'envoie à l'hote locale 192.168.0.68
html code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <html>
<head>
</head>
<body>
<p id="tst"></p>
<script>
document.getElementById("tst").innerHTML = "pas cliquer";
</script>
<script>
var exampleSocket;
function msg1(s)
{
document.getElementById("tst").innerHTML=s;
}
function tstweb()
{
//var proxy = process.env.http_proxy;
//console.log('using proxy server %j', proxy);
//exampleSocket = new WebSocket("wss://echo.websocket.org");
exampleSocket = new WebSocket("ws://192.168.0.68");
exampleSocket.onopen = function (event) { console.log("/!\\ Connexion serveur"); exampleSocket.send("test echo"); }
exampleSocket.onerror = function (event) { console.log(event); }
exampleSocket.onmessage = function (event) { console.log(event.data); msg1(event.data); }
exampleSocket.onclose = function (event) { console.log("/!\\ Déconnexion serveur"); }
}
</script>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click1" onclick="msg1('un')"/>
<input type="button" value="click2" onclick="tstweb()"/>
</form>
</body>
</html> |
alors dans les logs du serveur de l'hote j'observe :
Citation:
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 GET / HTTP/1.1
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 HOST 192.168.0.68
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 USER-AGENT Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 ACCEPT */*
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 ACCEPT-LANGUAGE fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 ACCEPT-ENCODING gzip, deflate
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 SEC-WEBSOCKET-VERSION 13
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 ORIGIN null
31/ 8/2020 17:24:14:356 (HTTP) ID:14198 SEC-WEBSOCKET-EXTENSIONS permessage-deflate
31/ 8/2020 17:24:14:372 (HTTP) ID:14198 SEC-WEBSOCKET-KEY 1zj8ioSBAvvNcvzXY//4zg==
31/ 8/2020 17:24:14:372 (HTTP) ID:14198 CONNECTION keep-alive, Upgrade
31/ 8/2020 17:24:14:372 (HTTP) ID:14198 PRAGMA no-cache
31/ 8/2020 17:24:14:372 (HTTP) ID:14198 CACHE-CONTROL no-cache
31/ 8/2020 17:24:14:372 (HTTP) ID:14198 UPGRADE websocket
31/ 8/2020 17:24:14:372 (HTTP) ID:14198 IP 192.168.0.27
31/ 8/2020 17:24:14:372 (HTTP) ID:14198 REMOTEHOST proxys.home
31/ 8/2020 17:24:14:372
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 GET / HTTP/1.1
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 HOST 192.168.0.68
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 USER-AGENT Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 ACCEPT */*
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 ACCEPT-LANGUAGE fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 ACCEPT-ENCODING gzip, deflate
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 SEC-WEBSOCKET-VERSION 13
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 ORIGIN null
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 SEC-WEBSOCKET-EXTENSIONS permessage-deflate
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 SEC-WEBSOCKET-KEY 2xnT40GSq3Nd7MpQGvtBSQ==
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 CONNECTION keep-alive, Upgrade
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 PRAGMA no-cache
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 CACHE-CONTROL no-cache
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 UPGRADE websocket
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 IP 192.168.0.27
31/ 8/2020 17:25:07:544 (HTTP) ID:14199 REMOTEHOST proxys.home
et je voudrais décoder le message '2xnT40GSq3Nd7MpQGvtBSQ=='
et ça me retourne une chaîne chinoise.
Programme C# qui décode :
Code:
1 2 3 4 5 6 7 8 9 10
| static void Main(string[] args)
{
var s = "2xnT40GSq3Nd7MpQGvtBSQ==";// + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
SHA1 sha = new SHA1CryptoServiceProvider();
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] combined = encoder.GetBytes(s);
// string hash = BitConverter.ToString(sha.ComputeHash(combined)).Replace("-", "");
string sd=encoder.GetString(sha.ComputeHash(combined));
Console.WriteLine(sd);
} |
Je ne retrouve pas la chaîne "test echo" mais plutôt une chaîne chinoise.
Je cherche à faire un site web hébergé chez moi et
je voudrais utiliser les API javascript websocket dans les page htm pour vérifier par exemple si le login/email existe déjà , ou pour lire l'heure du serveur et état du serveur etc.
Merci