Compare commits

...

2 Commits

10 changed files with 77 additions and 10 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
DotnetSystemd/bin/** */bin/**
DotnetSystemd/obj/** */obj/**
.nuget-packages .nuget-packages
result result
+11
View File
@@ -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>
+13
View File
@@ -0,0 +1,13 @@
using System.Net;
using System.Net.Sockets;
using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 9000));
Console.WriteLine("Type into the console to echo the contents of your message.");
var ns = new NetworkStream(socket);
var readTask = Console.OpenStandardInput().CopyToAsync(ns);
var writeTask = ns.CopyToAsync(Console.OpenStandardOutput());
await Task.WhenAny(readTask, writeTask);
+1
View File
@@ -0,0 +1 @@
[]
-2
View File
@@ -1,2 +0,0 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
+39
View File
@@ -0,0 +1,39 @@
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;
var message = System.Text.Encoding.Default.GetString(buffer[..read]);
Console.WriteLine($"Received new message: {message}");
await connection.SendAsync(buffer[..read], SocketFlags.None);
}
}
finally
{
connection.Dispose();
}
}
);
}
@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<RootNamespace>dotnet_systemd</RootNamespace> <RootNamespace>Server</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
+5
View File
@@ -0,0 +1,5 @@
<Solution>
<Folder Name="/Server/">
<Project Path="Server/Server.csproj" />
</Folder>
</Solution>
+5 -5
View File
@@ -23,11 +23,11 @@
in in
{ {
packages.default = pkgs.buildDotnetModule { packages.default = pkgs.buildDotnetModule {
pname = "dotnet-systemd"; pname = "Server";
version = "0.1.0"; version = "0.1.0";
src = ./DotnetSystemd; src = ./Server;
nugetDeps = ./DotnetSystemd/deps.json; nugetDeps = ./Server/deps.json;
dotnet-sdk = pkgs.dotnet-sdk_10; dotnet-sdk = pkgs.dotnet-sdk_10;
dotnet-runtime = dotnetRuntime; dotnet-runtime = dotnetRuntime;
@@ -42,8 +42,8 @@
mkdir -p $out/bin mkdir -p $out/bin
cp -r bin/Release/net10.0/* $out/bin/ cp -r bin/Release/net10.0/* $out/bin/
makeWrapper ${dotnetRuntime}/bin/dotnet $out/bin/dotnet-systemd \ makeWrapper ${dotnetRuntime}/bin/dotnet $out/bin/Server \
--add-flags "exec $out/bin/dotnet-systemd.dll" \ --add-flags "exec $out/bin/Server.dll" \
--prefix LD_LIBRARY_PATH : "${ --prefix LD_LIBRARY_PATH : "${
pkgs.lib.makeLibraryPath [ pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc.lib pkgs.stdenv.cc.cc.lib