refactor: modify into client server model
This commit is contained in:
+2
-2
@@ -1,4 +1,4 @@
|
||||
DotnetSystemd/bin/**
|
||||
DotnetSystemd/obj/**
|
||||
*/bin/**
|
||||
*/obj/**
|
||||
.nuget-packages
|
||||
result
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace>Client</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace>dotnet_systemd</RootNamespace>
|
||||
<RootNamespace>Server</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
@@ -0,0 +1,5 @@
|
||||
<Solution>
|
||||
<Folder Name="/Server/">
|
||||
<Project Path="Server/Server.csproj" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user