Closed mikewang68 closed 1 year ago
The Yew crew could chime in with a more specific answer, but because the WASM binary runs within the browser's sandbox and DOM, it can't interact with the kernel to open up arbitrary TCP sockets. However, you could do something like WebSocket or any of the other Fetch APIs exposed to regular web applications.
Problem
use std::io::{prelude::*, BufReader, Write}; use std::net::TcpStream; use std::str;
pub fn socket_client(s: &str) -> String { let mut stream = TcpStream::connect("127.0.0.1:10000").unwrap();
}
error yew-app-f2961ee15f0adfac.js:320 panicked at 'called
Result::unwrap()
on anErr
value: Error { kind: Unsupported, message: "operation not supported on this platform" }', src/socket.rs:6:60Stack:
Error at imports.wbg.wbg_new_abda76e883ba8a5f (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac.js:326:21) at console_error_panic_hook::Error::new::hcc273312b83619b5 (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[3676]:0x1002a6) at console_error_panic_hook::hook_impl::h6e828b44db16a989 (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[639]:0x88b8e) at console_error_panic_hook::hook::h27b20f480d424fbb (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[4092]:0x105ce2) at core::ops::function::Fn::call::hf927bad82efada78 (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[3510]:0xfd97a) at std::panicking::rust_panic_with_hook::hbafe3e603d331223 (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[1450]:0xc1762) at std::panicking::begin_panic_handler::{{closure}}::h8ab6ee68d5b4c391 (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[1881]:0xd54bc) at std::sys_common::backtrace::rust_end_short_backtrace::h008f69666d134159 (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[4282]:0x1082f8) at rust_begin_unwind (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[2949]:0xf34e1) at core::panicking::panic_fmt::h1d17fc068f528130 (http://127.0.0.1:8080/yew-app-f2961ee15f0adfac_bg.wasm:wasm-function[3919]:0x103979)
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Environment:
master
]nightly
]wasm32-unknown-emscripten
]wasm-pack
,trunk
]Questionnaire
how to solve it , if use tcp socket programming in yew ? thanks