This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const net = std.net; | |
const StreamServer = net.StreamServer; | |
const Options = StreamServer.Options; | |
const Address = net.Address; | |
pub fn main() anyerror!void { | |
const address = Address.initIp4([4]u8{ 127, 0, 0, 1 }, 8080); | |
var stream = StreamServer.init(Options{ .reuse_address = true }); | |
defer stream.deinit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | |
use tokio::net::TcpListener; | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let listener = TcpListener::bind("127.0.0.1:8080").await?; | |
loop { | |
let (mut socket, _) = listener.accept().await?; |