Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: add "Networking between browser windows/tabs using the Broadcast Channel API" #1196

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ See [tests/Readme.md](tests/Readme.md) for more information.
- [Programatically using the serial terminal](examples/serial.html)
- [A Lua interpreter](examples/lua.html)
- [Two instances in one window](examples/two_instances.html)
- [Networking between browser windows/tabs using the Broadcast Channel API](examples/broadcast-network.html)
- [Saving and restoring emulator state](examples/save_restore.html)

Using v86 for your own purposes is as easy as:
Expand Down
59 changes: 59 additions & 0 deletions examples/broadcast-network.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!doctype html>
<title>Networking via Broadcast Channel API</title>

<script src="../build/libv86.js"></script>
<script>
"use strict";

window.onload = function()
{
var emulator = window.emulator = new V86({
wasm_path: "../build/v86.wasm",
memory_size: 64 * 1024 * 1024,
vga_memory_size: 2 * 1024 * 1024,
screen_container: document.getElementById("screen_container"),
bios: {
url: "../bios/seabios.bin",
},
vga_bios: {
url: "../bios/vgabios.bin",
},
bzimage: {
url: "../images/buildroot-bzimage68.bin",
},
autostart: true,
});

var broadcast = new BroadcastChannel("v86-network");

broadcast.addEventListener("message", function(e) {
emulator.bus.send("net0-receive", e.data);
});
emulator.add_listener("net0-send", function(packet) {
broadcast.postMessage(packet);
});
}
</script>

<div id="screen_container">
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
<canvas style="display: none"></canvas>
</div>

<pre>
# Configure a static IP
ifconfig eth0 up arp 10.5.0.x

# Ping by IP
ping 10.5.0.x

# Run a DNS server and send a query (10.5.0.x for server, 10.5.0.y for record)
echo "anotherhost 10.5.0.y" | dnsd -c - -v - server
nslookup -type=a anotherhost 10.5.0.x - client

# Telnet calculator
socat TCP-L:23,fork exec:bc

# Simple HTTP server
socat TCP-L:80,crlf,fork system:'echo HTTP/1.1 200 OK;echo;lua /root/test.lua'
</pre>
Loading