https://github.com/ap-dev-at-home/ysocket
Library providing diverse means of socket communication.
https://github.com/ap-dev-at-home/ysocket
inter-process-communication ipc microservice-communication microservices named-pipes pipes sockets tcp udp
Last synced: 7 months ago
JSON representation
Library providing diverse means of socket communication.
- Host: GitHub
- URL: https://github.com/ap-dev-at-home/ysocket
- Owner: ap-dev-at-home
- License: mit
- Created: 2025-02-25T17:36:32.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-02-25T19:08:43.000Z (7 months ago)
- Last Synced: 2025-02-25T20:19:13.152Z (7 months ago)
- Topics: inter-process-communication, ipc, microservice-communication, microservices, named-pipes, pipes, sockets, tcp, udp
- Language: C#
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YSocket
YSocket is a C# Library to provide communication in the following categories
- Inter process
- Named Pipes
- Microservices (still working on it...)
- Tcp-Sockets
- Gaming (still working on it...)
- Udp-Sockets# Inter Process Communication (IPC)
PipeServer/PipeClient introduces an inter process communication model between processes based on c# class types, using named pipes.
Server and Client can setup their handlers on a shared class model and receive or send queries/commands on them.### Named Pipe Server
```csharp
using YSocket.Ipc;//- Setup Named Pipe Server
//- Register Command/Query Handlersclass ServerPipeHandler : IDisposable
{
private readonly PipeServer pipeServer;
public ServerPipeHandler(
CancellationToken? cancellationToken = null)
{
var pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule(
new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null),
PipeAccessRights.ReadWrite,
AccessControlType.Allow));this.pipeServer = new(Names.PIPE_SERVER_GUID, pipeSecurity, cancellationToken);
this.RegisterPipeHandlers();
this.pipeServer.Start();
}private void RegisterPipeHandlers()
{
this.pipeServer.Handle(exitCommand =>
{
//exitcommand received - stop application
});this.pipeServer.Handle(statusInformationQuery =>
{
//statusinformationquery received - respond
this.pipeServer.Send(new StatusInformation { ... });
});
}public void Dispose()
{
this.pipeServer.Dispose();
}
}
```### Named Pipe Client
```csharp
using YSocket.Ipc;//- Setup Named Pipe Client
//- Register Command/Query Handlersclass ClientPipeHandler : IDisposable
{
private readonly PipeClient pipeClient;
internal ClientPipeHandler(
CancellationToken? cancellationToken)
{
this.pipeClient = new(Names.PIPE_SERVER_GUID,
cancellationToken: cancellationToken);
}internal void RegisterPipeHandlers()
{
this.pipeClient.Handle(statusInformation =>
{
//process status information
});
}internal async Task Connect()
{
var retry = 0;
var success = false;do
{
success = await this.pipeClient.Connect(2500);
if (success == true)
{
break;
}
} while (retry++ < 3);return await Task.FromResult(success);
}internal bool QueryStatusInformation()
{
try
{
this.pipeClient.Send(new StatusInformationQuery());
}
catch (Exception ex)
{
return false;
}
return true;
}internal bool TerminateServer()
{
try
{
this.pipeClient.Send(new ExitCommand());
}
catch (Exception ex)
{
return false;
}
return true;
}public void Dispose()
{
this.pipeClient.Dispose();
}
}
```