first comm

This commit is contained in:
vman101 2025-02-11 19:12:35 +01:00
parent 427a466c1c
commit c9aaa698d1
7 changed files with 1248 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/alpine/*

1196
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "websockets"
version = "0.1.0"
edition = "2024"
[dependencies]
websocket = "*"

4
index.html Normal file
View File

@ -0,0 +1,4 @@
<body>
<iframe src="http://localhost:6080/vnc.html" width="800" height="600"></iframe>
</body>>

7
init.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
# Download alpine iso
wget https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-standard-3.19.0-x86_64.iso -O alpine/alpine.iso
# Create qemu volume
qemu-img create -f qcow2 alpine.qcow2 2

11
run.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
# run qemu vm
qemu-system-x86_64 \
-m 512M \
-hda alpine.qcow2 \
-cdrom alpine.iso \
-boot d \
-net nic -net user \
-vnc :1 \
-monitor telnet:127.0.0.1:5555,server,nowait

21
src/main.rs Normal file
View File

@ -0,0 +1,21 @@
use std::thread;
use websocket::Message;
use websocket::sync::Server;
fn main() {
let server = Server::bind("127.0.0.1:1234").unwrap();
for connection in server.filter_map(Result::ok) {
// Spawn a new thread for each connection.
thread::spawn(move || {
let mut client = connection.accept().unwrap();
let message = Message::text("Hello, client!");
let _ = client.send_message(&message);
let mess = client.recv_message();
println!("{:#?}", mess);
});
}
}