gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated: Improved websocket example allowi


From: gnunet
Subject: [libmicrohttpd] branch master updated: Improved websocket example allowing the client to connect to the remote host.
Date: Wed, 08 Apr 2020 18:56:15 +0200

This is an automated email from the git hooks/post-receive script.

silvioprog pushed a commit to branch master
in repository libmicrohttpd.

The following commit(s) were added to refs/heads/master by this push:
     new 2de4ad4c Improved websocket example allowing the client to connect to 
the remote host.
2de4ad4c is described below

commit 2de4ad4cafbe0a017b3494ada2cc430be30fbbf4
Author: silvioprog <address@hidden>
AuthorDate: Wed Apr 8 13:51:09 2020 -0300

    Improved websocket example allowing the client to connect to the remote 
host.
---
 src/examples/websocket_threaded_example.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/examples/websocket_threaded_example.c 
b/src/examples/websocket_threaded_example.c
index 21028901..9133190f 100644
--- a/src/examples/websocket_threaded_example.c
+++ b/src/examples/websocket_threaded_example.c
@@ -34,7 +34,7 @@
   "<title>WebSocket chat</title>\n"                                           \
   "<script>\n"                                                                \
   "document.addEventListener('DOMContentLoaded', function() {\n"              \
-  "  const ws = new WebSocket('ws://localhost:%d');\n"                        \
+  "  const ws = new WebSocket('ws://' + window.location.host);\n"             \
   "  const btn = document.getElementById('send');\n"                          \
   "  const msg = document.getElementById('msg');\n"                           \
   "  const log = document.getElementById('log');\n"                           \
@@ -54,6 +54,7 @@
   "  msg.onkeyup = function(ev) {\n"                                          \
   "    if (ev.keyCode === 13) {\n"                                            \
   "      ev.preventDefault();\n"                                              \
+  "      ev.stopPropagation();\n"                                             \
   "      btn.click();\n"                                                      \
   "      msg.value = '';\n"                                                   \
   "    }\n"                                                                   \
@@ -91,7 +92,7 @@
 #define WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
 #define WS_GUID_LEN 36
 #define WS_KEY_LEN 24
-#define WS_KEY_GUI_LEN ((WS_KEY_LEN) + (WS_GUID_LEN))
+#define WS_KEY_GUID_LEN ((WS_KEY_LEN) + (WS_GUID_LEN))
 #define WS_FIN 128
 #define WS_OPCODE_TEXT_FRAME 1
 #define WS_OPCODE_CON_CLOSE_FRAME 8
@@ -431,12 +432,9 @@ static int
 send_chat_page (struct MHD_Connection *con, uint16_t port)
 {
   struct MHD_Response *res;
-  char page[1024];
-  size_t page_len;
   int ret;
-  page_len = sprintf (page, CHAT_PAGE, port);
-  res = MHD_create_response_from_buffer (page_len, (void *) page,
-                                         MHD_RESPMEM_MUST_COPY);
+  res = MHD_create_response_from_buffer (strlen (CHAT_PAGE), (void *) 
CHAT_PAGE,
+                                         MHD_RESPMEM_PERSISTENT);
   ret = MHD_queue_response (con, MHD_HTTP_OK, res);
   MHD_destroy_response (res);
   return ret;
@@ -491,7 +489,7 @@ ws_get_accept_value (char *key, unsigned char **val)
   strcpy (str, key);
   strcat (str, WS_GUID);
   SHA1Reset (&ctx);
-  SHA1Input (&ctx, (const uint8_t *) str, WS_KEY_GUI_LEN);
+  SHA1Input (&ctx, (const uint8_t *) str, WS_KEY_GUID_LEN);
   SHA1Result (&ctx, hash);
   free (str);
   *val = BASE64Encode (hash, SHA1HashSize, NULL);

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]