Skip to content

Instantly share code, notes, and snippets.

View alichraghi's full-sized avatar
🏠
Working from home

Ali Cheraghi alichraghi

🏠
Working from home
View GitHub Profile
@alichraghi
alichraghi / zig-tcp.zig
Created September 10, 2021 11:11
Zig TCP Server
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();
@alichraghi
alichraghi / simple-tokio-server.rs
Last active November 20, 2022 17:44
Simple Tokio Server
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?;