Rust & Zig

This commit is contained in:
Johan Maasing 2025-01-17 13:28:30 +01:00
parent ea4ef1d8b3
commit c2e16f5b83
11 changed files with 226 additions and 15 deletions

View file

@ -15,21 +15,30 @@ public class Main {
new Main().run();
}
private void run() throws IOException {
private void run() {
try (var clientChannel = SocketChannel.open(StandardProtocolFamily.UNIX)) {
var serverPath = Path.of("/tmp").resolve("udsserver.sock") ;
var serverAddress = UnixDomainSocketAddress.of(serverPath);
clientChannel.connect(serverAddress);
var clientMessage = "quit från - " + UUID.randomUUID();
var clientMessage = "Hello world from Java";
sendMessage(clientMessage, clientChannel);
}
}
var messageBytes = clientMessage.getBytes(StandardCharsets.UTF_8);
var messageBuffer = ByteBuffer.allocate(400);
messageBuffer.put((byte) messageBytes.length);
messageBuffer.put(messageBytes);
messageBuffer.flip();
while (messageBuffer.hasRemaining()) {
clientChannel.write(messageBuffer);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static void sendMessage(String clientMessage, SocketChannel clientChannel) throws IOException {
var messageBytes = clientMessage.getBytes(StandardCharsets.UTF_8);
var messageBuffer = ByteBuffer.allocate(500);
var messageBuffer = ByteBuffer.allocate(400);
messageBuffer.put((byte) messageBytes.length);
messageBuffer.put(messageBytes);
messageBuffer.flip();