Skip to content
Closed
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
100 changes: 86 additions & 14 deletions frameworks/wtx-ws/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frameworks/wtx-ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"

[dependencies]
tokio = { default-features = false, features = ["macros", "rt-multi-thread"], version = "1.0" }
wtx = { default-features = false, features = ["crypto-ring", "optimizations", "optioned-server", "tokio", "web-socket-handshake"], version = "0.47" }
wtx = { default-features = false, features = ["crypto-ring", "optimizations-std", "tokio", "web-socket-server-framework"], git = "https://github.com/c410-f3r/wtx", branch = "misc" }

[profile.release]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion frameworks/wtx-ws/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM rust:1.95 AS build
RUN rustup default nightly-2026-05-07
RUN rustup default nightly-2026-06-27
WORKDIR /app
COPY Cargo.toml .
RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release && rm -rf src/ target/release/httparena-wtx-ws* target/release/deps/httparena_wtx-ws*
Expand Down
2 changes: 1 addition & 1 deletion frameworks/wtx-ws/meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"display_name": "wtx",
"language": "Rust",
"type": "engine",
"type": "emerging",
"engine": "wtx",
"description": "WTX - WebSocket Server",
"repo": "https://github.com/c410-f3r/wtx",
Expand Down
42 changes: 13 additions & 29 deletions frameworks/wtx-ws/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
use tokio::net::TcpStream;
use wtx::{
collection::Vector,
http::OptionedServer,
rng::Xorshift64,
web_socket::{OpCode, WebSocket, WebSocketBuffer, WebSocketPayloadOrigin},
collections::Vector,
executor::TokioExecutor,
http::WebSocketServerFramework,
tls::{TlsConfig, TlsModePlainText},
web_socket::{OpCode, WebSocket, WebSocketPayloadOrigin},
};

fn main() {
let threads = std::thread::available_parallelism().map(|el| el.get()).unwrap_or(1);
let mut handlers = Vector::new();
for _ in 0..threads {
let handle = std::thread::spawn(move || {
tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
let cb = (|| Ok(()), |_, stream| async move { Ok(stream) });
let _el = OptionedServer::web_socket_tokio("0.0.0.0:8080", || {}, |_| {}, handle, cb).await;
});
});
handlers.push(handle).unwrap();
}
for handle in handlers {
handle.join().unwrap();
}
type LocalWebSocket = WebSocket<(), TcpStream, TlsModePlainText, false>;

fn main() -> wtx::Result<()> {
WebSocketServerFramework::new(TokioExecutor::default(), TlsConfig::empty().into())?
.run_in_threads("0.0.0.0:8080", (("/ws", ws),))
}

async fn handle(
path: String,
mut ws: WebSocket<(), Xorshift64, TcpStream, WebSocketBuffer, false>,
) -> wtx::Result<()> {
if path != "/ws" {
return Ok(());
}
async fn ws(mut buffer: Vector<u8>, mut ws: LocalWebSocket) -> wtx::Result<()> {
let (mut common, mut reader, mut writer) = ws.split_mut();
let payload_origin = WebSocketPayloadOrigin::Adaptive;
let mut buffer = path.into_bytes().into();
loop {
let Ok(mut frame) = reader.read_frame(&mut buffer, &mut common, payload_origin).await else {
let origin = WebSocketPayloadOrigin::Adaptive;
let Ok(mut frame) = reader.read_frame(&mut buffer, &mut common, origin).await else {
return Ok(());
};
match frame.op_code() {
Expand Down