初始化

This commit is contained in:
邵静 2024-06-17 14:06:23 +08:00
commit 12bf876664
3 changed files with 43 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.zig-cache/*
zig-out/*

18
build.zig Normal file
View File

@ -0,0 +1,18 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "crun",
.target = target,
.optimize = optimize,
});
exe.addCSourceFile(.{ .file = b.path("main.c"), .flags = &.{} });
exe.linkSystemLibrary("zmq");
exe.linkLibC();
b.installArtifact(exe);
}

23
main.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <zmq.h>
int main(void) {
printf("Connecting to hello world server…\n");
void *context = zmq_ctx_new();
void *requester = zmq_socket(context, ZMQ_REQ);
zmq_connect(requester, "tcp://localhost:5555");
int request_nbr;
for (request_nbr = 0; request_nbr != 10; request_nbr++) {
char buffer[10];
printf("Sending Hello %d…\n", request_nbr);
zmq_send(requester, "Hello", 5, 0);
zmq_recv(requester, buffer, 10, 0);
printf("Received from Server %s\n", buffer);
}
zmq_close(requester);
zmq_ctx_destroy(context);
return 0;
}