From 3e6426c655ae44f9c409a6069f6d52a6b773626c Mon Sep 17 00:00:00 2001 From: Frank LoTurco Date: Wed, 20 May 2026 12:08:12 -0400 Subject: [PATCH] refactor: modify into client server model --- .gitignore | 4 +-- Client/Client.csproj | 11 ++++++ {DotnetSystemd => Client}/Program.cs | 0 Client/deps.json | 1 + Server/Program.cs | 35 +++++++++++++++++++ .../Server.csproj | 2 +- {DotnetSystemd => Server}/deps.json | 0 dotnet-systemd.slnx | 5 +++ flake.nix | 8 ++--- 9 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 Client/Client.csproj rename {DotnetSystemd => Client}/Program.cs (100%) create mode 100644 Client/deps.json create mode 100644 Server/Program.cs rename DotnetSystemd/dotnet-systemd.csproj => Server/Server.csproj (87%) rename {DotnetSystemd => Server}/deps.json (100%) create mode 100644 dotnet-systemd.slnx diff --git a/.gitignore b/.gitignore index 6cf84f1..49f0faa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -DotnetSystemd/bin/** -DotnetSystemd/obj/** +*/bin/** +*/obj/** .nuget-packages result diff --git a/Client/Client.csproj b/Client/Client.csproj new file mode 100644 index 0000000..63cfc9f --- /dev/null +++ b/Client/Client.csproj @@ -0,0 +1,11 @@ + + + + Exe + net10.0 + Client + enable + enable + + + diff --git a/DotnetSystemd/Program.cs b/Client/Program.cs similarity index 100% rename from DotnetSystemd/Program.cs rename to Client/Program.cs diff --git a/Client/deps.json b/Client/deps.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/Client/deps.json @@ -0,0 +1 @@ +[] diff --git a/Server/Program.cs b/Server/Program.cs new file mode 100644 index 0000000..b6f1472 --- /dev/null +++ b/Server/Program.cs @@ -0,0 +1,35 @@ +using System.Net; +using System.Net.Sockets; + +using var listener = new Socket(SocketType.Stream, ProtocolType.Tcp); +listener.Bind(new IPEndPoint(IPAddress.Loopback, 9000)); + +Console.WriteLine($"Listening on {listener.LocalEndPoint}"); + +listener.Listen(); + +while (true) +{ + var connection = await listener.AcceptAsync(); + + _ = Task.Run(async () => + { + + var buffer = new byte[4096]; + try + { + while (true) + { + int read = await connection.ReceiveAsync(buffer, SocketFlags.None); + if (read == 0) break; + + await connection.SendAsync(buffer[..read], SocketFlags.None); + } + } + finally + { + connection.Dispose(); + } + } + ); +} diff --git a/DotnetSystemd/dotnet-systemd.csproj b/Server/Server.csproj similarity index 87% rename from DotnetSystemd/dotnet-systemd.csproj rename to Server/Server.csproj index 46dce4b..cc1bbd6 100644 --- a/DotnetSystemd/dotnet-systemd.csproj +++ b/Server/Server.csproj @@ -3,7 +3,7 @@ Exe net10.0 - dotnet_systemd + Server enable enable diff --git a/DotnetSystemd/deps.json b/Server/deps.json similarity index 100% rename from DotnetSystemd/deps.json rename to Server/deps.json diff --git a/dotnet-systemd.slnx b/dotnet-systemd.slnx new file mode 100644 index 0000000..9be07b8 --- /dev/null +++ b/dotnet-systemd.slnx @@ -0,0 +1,5 @@ + + + + + diff --git a/flake.nix b/flake.nix index c5fae64..267e3b6 100644 --- a/flake.nix +++ b/flake.nix @@ -25,9 +25,9 @@ packages.default = pkgs.buildDotnetModule { pname = "dotnet-systemd"; version = "0.1.0"; - src = ./DotnetSystemd; + src = ./Server; - nugetDeps = ./DotnetSystemd/deps.json; + nugetDeps = ./Server/deps.json; dotnet-sdk = pkgs.dotnet-sdk_10; dotnet-runtime = dotnetRuntime; @@ -42,8 +42,8 @@ mkdir -p $out/bin cp -r bin/Release/net10.0/* $out/bin/ - makeWrapper ${dotnetRuntime}/bin/dotnet $out/bin/dotnet-systemd \ - --add-flags "exec $out/bin/dotnet-systemd.dll" \ + makeWrapper ${dotnetRuntime}/bin/dotnet $out/bin/Server \ + --add-flags "exec $out/bin/Server.dll" \ --prefix LD_LIBRARY_PATH : "${ pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib