refactor: add simple c# client

This commit is contained in:
k0t9i
2023-01-26 01:36:49 +04:00
parent eb7bfc779b
commit 7ad3ff4081
9 changed files with 116 additions and 281 deletions

View File

@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<BaseOutputPath>$(SolutionDir)$(Configuration)\bin\</BaseOutputPath>
<BaseIntermediateOutputPath>$(SolutionDir)$(Configuration)\$(MSBuildProjectName)\obj\</BaseIntermediateOutputPath>
<MSBuildProjectExtensionsPath>$(SolutionDir)$(Configuration)\$(MSBuildProjectName)\ext\</MSBuildProjectExtensionsPath>
<PackageOutputPath>$(BaseOutputPath)</PackageOutputPath>
<OutputPath>$(BaseOutputPath)</OutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
</PropertyGroup>
</Project>

57
TestClient/Program.cs Normal file
View File

@@ -0,0 +1,57 @@
using System.IO;
using System.IO.Pipes;
using System.Text;
internal class Program
{
private static void Main(string[] args)
{
while (true)
{
var clientPipe = new NamedPipeClientStream("PipeL2Bot");
clientPipe.Connect();
clientPipe.ReadMode = PipeTransmissionMode.Message;
Console.WriteLine("Connected to connection pipe");
byte[] buffer = new byte[16384 * 2];
int read = clientPipe.Read(buffer, 0, buffer.Length);
if (clientPipe.IsConnected)
{
string pipeName = Encoding.Unicode.GetString(buffer).TrimEnd('\0');
Console.WriteLine("Received connection pipe name " + pipeName);
var mainPipe = new NamedPipeClientStream(pipeName);
mainPipe.Connect();
mainPipe.ReadMode = PipeTransmissionMode.Message;
Console.WriteLine("Connected to main pipe");
while (true)
{
byte[] buffer1 = new byte[16384 * 2];
int read1 = mainPipe.Read(buffer1, 0, buffer1.Length);
if (mainPipe.IsConnected)
{
string message = Encoding.Unicode.GetString(buffer1).TrimEnd('\0');
Console.WriteLine(message);
}
else
{
Console.WriteLine("Disconnected from main pipe");
Console.WriteLine("Disconnected from connection pipe");
mainPipe.Close();
mainPipe.Dispose();
clientPipe.Close();
clientPipe.Dispose();
break;
}
}
}
}
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>