examples: give clients network addresses
This commit is contained in:
@@ -7,6 +7,7 @@ const assertSometimes = Simulator.assertSometimes;
|
|||||||
const reachableSometimes = Simulator.reachableSometimes;
|
const reachableSometimes = Simulator.reachableSometimes;
|
||||||
|
|
||||||
const server_ip = net.Ip4Address.loopback(9090);
|
const server_ip = net.Ip4Address.loopback(9090);
|
||||||
|
const client_ip = net.Ip4Address{ .bytes = .{ 127, 0, 0, 2 }, .port = 0 };
|
||||||
const server_address: net.IpAddress = .{ .ip4 = server_ip };
|
const server_address: net.IpAddress = .{ .ip4 = server_ip };
|
||||||
const payload = "payload:v1:write-sync-rename-send";
|
const payload = "payload:v1:write-sync-rename-send";
|
||||||
const ack = "ack";
|
const ack = "ack";
|
||||||
@@ -169,6 +170,7 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
|
|
||||||
fn runSimulation(init: std.process.Init, seed: u64) !void {
|
fn runSimulation(init: std.process.Init, seed: u64) !void {
|
||||||
const server_addresses = [_]u32{std.mem.readInt(u32, &server_ip.bytes, .big)};
|
const server_addresses = [_]u32{std.mem.readInt(u32, &server_ip.bytes, .big)};
|
||||||
|
const client_addresses = [_]u32{std.mem.readInt(u32, &client_ip.bytes, .big)};
|
||||||
|
|
||||||
var sim: Simulator = undefined;
|
var sim: Simulator = undefined;
|
||||||
sim.init(std.heap.page_allocator, init.io, seed);
|
sim.init(std.heap.page_allocator, init.io, seed);
|
||||||
@@ -190,7 +192,7 @@ fn runSimulation(init: std.process.Init, seed: u64) !void {
|
|||||||
try sim.addExecutable("client", clientProgram);
|
try sim.addExecutable("client", clientProgram);
|
||||||
|
|
||||||
try sim.spawn("server", .{ .addresses = &server_addresses });
|
try sim.spawn("server", .{ .addresses = &server_addresses });
|
||||||
try sim.spawn("client", .{});
|
try sim.spawn("client", .{ .addresses = &client_addresses });
|
||||||
|
|
||||||
while (sim.scheduleOne()) {}
|
while (sim.scheduleOne()) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const net = Io.net;
|
|||||||
const Simulator = @import("zigmulator");
|
const Simulator = @import("zigmulator");
|
||||||
|
|
||||||
const server_ip = net.Ip4Address.loopback(8080);
|
const server_ip = net.Ip4Address.loopback(8080);
|
||||||
|
const client_ip = net.Ip4Address{ .bytes = .{ 127, 0, 0, 2 }, .port = 0 };
|
||||||
const server_address: net.IpAddress = .{ .ip4 = server_ip };
|
const server_address: net.IpAddress = .{ .ip4 = server_ip };
|
||||||
|
|
||||||
fn serverProgram(init: std.process.Init) anyerror!void {
|
fn serverProgram(init: std.process.Init) anyerror!void {
|
||||||
@@ -61,6 +62,7 @@ fn clientProgram(init: std.process.Init) anyerror!void {
|
|||||||
|
|
||||||
pub fn main(init: std.process.Init) !void {
|
pub fn main(init: std.process.Init) !void {
|
||||||
const server_addresses = [_]u32{std.mem.readInt(u32, &server_ip.bytes, .big)};
|
const server_addresses = [_]u32{std.mem.readInt(u32, &server_ip.bytes, .big)};
|
||||||
|
const client_addresses = [_]u32{std.mem.readInt(u32, &client_ip.bytes, .big)};
|
||||||
|
|
||||||
var sim: Simulator = undefined;
|
var sim: Simulator = undefined;
|
||||||
sim.init(std.heap.page_allocator, init.io, 0);
|
sim.init(std.heap.page_allocator, init.io, 0);
|
||||||
@@ -72,7 +74,7 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
try sim.addExecutable("client", clientProgram);
|
try sim.addExecutable("client", clientProgram);
|
||||||
|
|
||||||
try sim.spawn("server", .{ .addresses = &server_addresses });
|
try sim.spawn("server", .{ .addresses = &server_addresses });
|
||||||
try sim.spawn("client", .{});
|
try sim.spawn("client", .{ .addresses = &client_addresses });
|
||||||
|
|
||||||
while (sim.scheduleOne()) {}
|
while (sim.scheduleOne()) {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user