-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathtcp_terminal.html
144 lines (125 loc) · 3.98 KB
/
tcp_terminal.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!doctype html>
<title>TCP Terminal</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",
},
net_device: {
relay_url: "fetch",
type: "virtio"
},
autostart: true
});
var is_connected = false, connection = null;
function clear_log()
{
document.getElementById("log").value = "";
}
function write_log(text)
{
document.getElementById("log").value += text;
}
function on_connect()
{
document.getElementById("connect").innerHTML = "Disconnect";
document.getElementById("send").disabled = false;
is_connected = true;
}
function on_disconnect()
{
document.getElementById("connect").innerHTML = "Connect";
document.getElementById("send").disabled = true;
is_connected = false;
}
document.getElementById("connect").onclick = async function() {
if(!is_connected)
{
clear_log();
let port = parseInt(document.getElementById("port").value);
write_log("> Probing port " + port + "\n");
let open = await emulator.network_adapter.tcp_probe(port);
if(open)
{
connection = emulator.network_adapter.connect(port);
connection.on("connect", function()
{
write_log("> Connected\n\n");
on_connect();
});
connection.on("data", function(data)
{
write_log(new TextDecoder().decode(data));
});
connection.on("close", function()
{
write_log("\n> Closed by listener");
on_disconnect();
});
connection.on("shutdown", function()
{
write_log("\n> Shutdown by listener");
on_disconnect();
});
}
else
{
write_log("> Probing failed");
}
}
else
{
connection.close();
write_log("\n> Closed by client");
on_disconnect();
}
}
document.getElementById("send").onclick = function()
{
connection.write(new TextEncoder().encode(document.getElementById("prompt").value + "\r\n"));
document.getElementById("prompt").value = "";
}
document.getElementById("prompt").onkeydown = function(e)
{
if(e.which == 13 && is_connected)
{
document.getElementById("send").onclick();
}
};
clear_log();
}
</script>
<div id="screen_container" style="float: left">
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
<canvas style="display: none"></canvas>
</div>
<div style="float: left; margin: 10px">
<textarea readonly cols="60" rows="15" id="log"></textarea><br>
Port: <input type="number" min="1" max="65535" value="1234" id="port" />
<button id="connect">Connect</button> <input type="text" id="prompt" />
<button id="send" disabled="true">Send (enter)</button>
<h3>Getting started</h3>
<ol>
<li>Run <code>udhcpc</code></li>
<li>Run any TCP server:
<ul>
<li>Echo: <code>socat -v PIPE TCP-L:1234,fork</code></li>
<li>(more examples on <a href="broadcast-network.html">broadcast-network.html</a>)</li>
</ul>
<li>Type a port number and press "Connect"</li>
</ol>
</div>