I want to have an (ideally) single threaded server, that can accept clients without blocking. Is there a way to check if a client wants to connect, or am I forced to go multithreaded?
Same question for reading what a client is sending btw
Hi! These might be promising solutions to explore:
Thank you, is one of these is tcp? I forgot to mention that im making a tcp server
Yeah, libxev has a TCP client/server.
Ah okay thank you
Yikes ive updated zig and now i dont know how to make a server lol
If anyone knows how to please tell me
Where is my streamserver
I genuinely cant manage to read this anytype magic
Where is this “xev” defined?
It’s defined for you from one of these based on your OS. See if you can figure out how to set up a TCP client/server from this benchmark. I still couldn’t quite do that, yet
Oh sorry, the way I phrased that was missleading. I am doing this for a school project so I dont wanna use any libs except std. (Also to keep it relatively simple)
I was asking if you (or someone else for that matter) knows how to make a server with std.net
master.
(Ideally but obv optionally with code samples)
The tests for std.net
are really good sample code. That link goes straight to the test for a simple TCP serving scenario.
OHHH THATS GENIUSS the made it a method of address I LOVE IT thank you so much
If you want to have a single threaded server, you can use std.io.poll
:
zig/lib/std/io.zig at 5c0766b6c8f1aea18815206e0698953a35384a21 · ziglang/zig · GitHub.
For an example see zig/lib/std/child_process.zig at 5c0766b6c8f1aea18815206e0698953a35384a21 · ziglang/zig · GitHub.
An alternative is to use directly epoll
, poll
or select
, depending on the OS you are using.
Thank you, I will take a look at this!
epoll based example
When client connects, this function is invoked by the engine.
I am not sure that usage of std.io.poll is good idea for sockets
According to introduce std.io.poll it was intended for pipes
Let’s discuss