kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

frontend.html (1044B)



      1 <!DOCTYPE>
      2 <html>
      3 <head>
      4 <script>
      5 var socket = null;
      6 var sent = 0;
      7 var recv = 0;
      8 var length = 65536;
      9 
     10 function open(evt) {
     11 	var msg = "";
     12 	var alphabet = "abcdefghijklmnopqrstuvwxyz";
     13 
     14 	for (i = 0; i < length; i++)
     15 		msg += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
     16 
     17 	message(msg);
     18 }
     19 
     20 function message(msg) {
     21 	socket.send(msg);
     22 	sent = sent + 1;
     23 	update();
     24 }
     25 
     26 function update() {
     27 	var cnt = document.getElementById("counter");
     28 
     29 	cnt.innerHTML = "Recv: " + recv + " Sent: " + sent;
     30 }
     31 
     32 function onmessage(evt) {
     33 	recv = recv + 1;
     34 	update();
     35 
     36 	message(evt.data);
     37 }
     38 
     39 function connect() {
     40 	socket = new WebSocket("wss://127.0.0.1:8888/connect");
     41 
     42 	socket.onopen = function(evt) { open(evt) };
     43 	socket.onclose = function(evt) { alert("closed"); };
     44 	socket.onmessage = function(evt) { onmessage(evt) };
     45 	socket.onerror = function(evt) { alert("onerror"); };
     46 }
     47 </script>
     48 </head>
     49 
     50 <body>
     51 
     52 <form action="/" onsubmit="connect(); return false;">
     53 <input type="submit" value="connect">
     54 </form>
     55 
     56 <div id="counter">
     57 </div>
     58 
     59 </body>
     60 </html>