我正在尝试在不同的线程中使用 tcp 流的读写。这就是我目前所拥有的:
use tokio::prelude::*;
use tokio::net::TcpStream;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut stream = TcpStream::connect("localhost:8080").await?;
let (mut read, mut write) = stream.split();
tokio::spawn(async move {
loop {
let mut buf = [0u8; 32];
read.read(&mut buf).await.unwrap();
println!("{}", std::str::from_utf8(&buf));
}
});
Ok(())
}
Run Code Online (Sandbox Code Playgroud)
我将使用另一个线程进行写入。我的问题是,我收到“流”在借用时被丢弃的错误。
我正在尝试将 ESP8266 连接到另一个 ESP8266 托管的 WiFi 网络。问题是 ESP8266 在 WiFi 扫描期间显示 WiFi 网络,但无法连接到它并出现错误:no espnetwork found, reconnect after 1s。
ESP8266 托管网络的代码:
#include <osapi.h>
#include <user_interface.h>
void ICACHE_FLASH_ATTR user_init(void) {
// Delays 1 second for my serial monitor to catch up
for (int i = 0; i < 200; i++) os_delay_us(5000);
gpio_init();
uart_init(115200, 115200);
wifi_softap_dhcps_stop();
wifi_set_opmode(SOFTAP_MODE);
struct softap_config softAPConfig = {
.ssid = {0},
.password = {0},
.ssid_len = sizeof("espnetwork"),
.authmode = AUTH_OPEN,
.max_connection = 4,
.beacon_interval = 100,
}; …Run Code Online (Sandbox Code Playgroud)