ikskuh/zig-network
소개
크로스 플랫폼 네트워킹을 위한 소켓 함수의 최소 공통 부분집합으로, TCP와 UDP를 지원합니다.
시스템 및 인프라What you can do
- Implements the minimal API surface for basic networking
- Makes cross-platform abstractions
- Supports blocking and non-blocking I/O via select/poll
- UDP multicast support
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalZig Network Abstraction
Small network abstraction layer around TCP & UDP.
Features
- Implements the minimal API surface for basic networking
- Makes cross-platform abstractions
- Supports blocking and non-blocking I/O via
select/poll - UDP multicast support
Usage
Use with the package manager
build.zig.zon:
.{
.name = "appname",
.version = "0.0.0",
.dependencies = .{
.network = .{
.url = "https://github.com/MasterQ32/zig-network/archive/<COMMIT_HASH_HERE>.tar.gz",
.hash = "HASH_GOES_HERE",
},
},
}
(To aquire the hash, please remove the line containing .hash, the compiler will then tell you which line to put back)
build.zig:
exe.addModule("network", b.dependency("network", .{}).module("network"));
Usage example
const network = @import("network");
test "Connect to an echo server" {
try network.init();
defer network.deinit();
const sock = try network.connectToHost(std.heap.page_allocator, "tcpbin.com", 4242, .tcp);
defer sock.close();
const msg = "Hi from socket!\n";
try sock.writer().writeAll(msg);
var buf: [128]u8 = undefined;
std.debug.print("Echo: {}", .{buf[0..try sock.reader().readAll(buf[0..msg.len])]});
}
See async.zig for a more complete example on how to use asynchronous I/O to make a small TCP server.
Run examples
Build all examples:
$ zig build examples
Build a specific example:
$ zig build sync-examples
To test an example, eg. echo:
$ ./zig-out/bin/echo 3000
in another terminal
$ nc localhost 3000
hello
hello
how are you
how are you
Notes
On Windows receive and send function calls are asynchronous and cooperate with the standard library event loop
when io_mode = .evented is set in the root file of your program.
Other calls (connect, listen, accept etc) are blocking.
관련 프로젝트 살펴보기
불러오는 중…