broadcast-network.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!doctype html>
  2. <title>Networking via Broadcast Channel API</title>
  3. <script src="../build/libv86.js"></script>
  4. <script>
  5. "use strict";
  6. window.onload = function()
  7. {
  8. var emulator = window.emulator = new V86({
  9. wasm_path: "../build/v86.wasm",
  10. memory_size: 64 * 1024 * 1024,
  11. vga_memory_size: 2 * 1024 * 1024,
  12. screen_container: document.getElementById("screen_container"),
  13. bios: {
  14. url: "../bios/seabios.bin",
  15. },
  16. vga_bios: {
  17. url: "../bios/vgabios.bin",
  18. },
  19. bzimage: {
  20. url: "../images/buildroot-bzimage68.bin",
  21. },
  22. autostart: true,
  23. });
  24. var broadcast = new BroadcastChannel("v86-network");
  25. broadcast.addEventListener("message", function(e) {
  26. emulator.bus.send("net0-receive", e.data);
  27. });
  28. emulator.add_listener("net0-send", function(packet) {
  29. broadcast.postMessage(packet);
  30. });
  31. }
  32. </script>
  33. <div id="screen_container">
  34. <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
  35. <canvas style="display: none"></canvas>
  36. </div>
  37. <pre>
  38. # This example allows network across multiple browser tabs by using BroadcastChannels.
  39. # Configure a static IP
  40. ifconfig eth0 up arp 10.5.0.x
  41. # Ping by IP
  42. ping 10.5.0.x
  43. # Run a DNS server and send a query (10.5.0.x for server, 10.5.0.y for record)
  44. echo "anotherhost 10.5.0.y" | dnsd -c - -v - server
  45. nslookup -type=a anotherhost 10.5.0.x - client
  46. # Telnet calculator
  47. socat TCP-L:23,fork exec:bc
  48. # Simple HTTP server
  49. socat TCP-L:80,crlf,fork system:'echo HTTP/1.1 200 OK;echo;lua /root/test.lua'
  50. </pre>