Finding if port is closed when connecting to UDP server

Hello Everybody hope yall having wonderful day. I need a just quick help am working on an enumeration tool for SNMP. The issue is when i connect to udp port it’s normal that idk if it open or closed, however when sending or receiving i should know then at least that what the normal send, recv syscalls does. Here is the code example am working on.

fn connectSnmp(ip: net.IpAddress, io: Io) !net.Stream {
    const stream = try ip.connect(io, .{ .mode = .dgram, .protocol = .udp, .timeout = .none });
    return stream;
}

pub fn main(init: std.process.Init) !void {
    const io = init.io;
    var gpa = std.heap.DebugAllocator(.{ .verbose_log = true }){};
    const allocator = gpa.allocator();
    _ = allocator;

    const ip = try net.IpAddress.parse("127.0.0.1", 161);

    const stream = try connectSnmp(ip, io);
    var write_buf: [1024]u8 = undefined;
    var writer_handler = stream.writer(io, &write_buf);

    const writer_server = &writer_handler.interface;
    const written = try writer_server.write("Hello world");
    try writer_server.flush();
    _ = written;

    defer stream.close(io);
    std.log.debug("{any}", .{stream.socket.handle});
}

Also i tried to setting a timeout but unfortunately its not implemented yet i got a panic that stated that

Im not sure I fully understand, but maybe this here will help: Your io interface from init is probably an erased Threaded and if you connect (.netConnectIp) it uses the os impl. You can trace the function bodys for what you want to know.
For snmp I believe you need to write a request and read a response with a timeout to see if someone is listening.

For UDP, it’s better to use the IpAddress.bind, then use the resulting socket to send and receiveTimeout.

Oh thanks that exactly what i was looking for. However is this buffered and if not how can i make it buffered ?

Usually when working with UDP, you work with datagrams (buffers) and a sent message should not exceed the network MTU (1500 bytes max) to avoid fragmentation/truncation.
So take a buffer, use std.Io.Writer.fixed and write to it, then send the buffered data.

Appreciated bro. Really helpful Thank you