Przeglądaj źródła

Improve echo web UI

Based on feedback from anon.
Gary Burd 10 lat temu
rodzic
commit
361d4c0ffd
2 zmienionych plików z 12 dodań i 6 usunięć
  1. 1 3
      examples/echo/README.md
  2. 11 3
      examples/echo/server.go

+ 1 - 3
examples/echo/README.md

@@ -14,6 +14,4 @@ Next, start the client:
     $ go run client.go
 
 The server includes a simple web client. To use the client, open
-http://127.0.0.1:8080 in the browser. Click "Open" to open a connection to the
-server, "Send" to send a message to the server and "Close" to close the
-connection.
+http://127.0.0.1:8080 in the browser and follow the instructions on the page.

+ 11 - 3
examples/echo/server.go

@@ -65,9 +65,9 @@ window.addEventListener("load", function(evt) {
     var ws;
 
     var print = function(message) {
-        var p = document.createElement("p");
-        p.innerHTML = message;
-        output.appendChild(p);
+        var d = document.createElement("div");
+        d.innerHTML = message;
+        output.appendChild(d);
     };
 
     document.getElementById("open").onclick = function(evt) {
@@ -112,13 +112,21 @@ window.addEventListener("load", function(evt) {
 </script>
 </head>
 <body>
+<table>
+<tr><td valign="top" width="50%">
+<p>Click "Open" to create a connection to the server, 
+"Send" to send a message to the server and "Close" to close the connection. 
+You can change the message and send multiple times.
+<p>
 <form>
 <button id="open">Open</button>
 <button id="close">Close</button>
 <p><input id="input" type="text" value="Hello world!">
 <button id="send">Send</button>
 </form>
+</td><td valign="top" width="50%">
 <div id="output"></div>
+</td></tr></table>
 </body>
 </html>
 `))