Documentation Index
Fetch the complete documentation index at: https://mintlify.com/FarlandsModdingTeam/TerbinProyect/llms.txt
Use this file to discover all available pages before exploring further.
TerbinCommunicator is the central class of the Terbin framework. It wraps a Windows named pipe — either a server-side NamedPipeServerStream or a client-side NamedPipeClientStream — and drives the complete lifecycle of the connection: accepting a client, queuing outbound packets, reading inbound packets on a background loop, and correlating awaited responses back to their calling code.
Constructor
When
true, the communicator creates a NamedPipeServerStream and immediately begins waiting for the first client connection. When false, a NamedPipeClientStream is created — call Connect() or TryConnect() to establish the link.Controls the lifetime of the internal send and receive background loops. Cancel this token to stop both loops cleanly.
The named-pipe identifier visible to the operating system. Both sides of a connection must use the same name.
TerbinExecutor.Init(this), which registers all internal protocol handlers (Load, Solicit, Response, Prolong) with the global TerbinExecutableManager.
Key Properties
IsServer
bool — true when the instance was created in server mode. Read-only after construction.IsConnect
bool — reflects the live IsConnected state of the underlying PipeStream. Returns false if the pipe is null.MaximumResponseTime
ushort — seconds before a Communicate() call times out. Defaults to TerbinProtocol.MAXIMUS_RESPONSE_TIME (8 seconds). Can be changed at any time.Connecting
Connect()
ConnectAsync() on the underlying NamedPipeClientStream and then starts the background send and receive loops. Returns true on success. Only valid when IsServer = false.
TryConnect()
false if the pipe is already connected or if the instance is a server. Use this for safe reconnection attempts in client code.
Sending Data
Terbin distinguishes between fire-and-forget sends and awaited request-response pairs.Send()
null when the payload fits in a single packet (≤ MAX_PLD). If fragmentation is required and the CheckExecution handshake or memory allocation fails, the returned PacketRequest carries the error status — otherwise null is also returned on successful fragmentation.
SendBytes()
params. Useful for short control signals.
Communicate()
TaskCompletionSource keyed by the packet ID. When the peer sends back a packet with the same IdRequest, the internal Response handler resolves the TCS and this method returns.
Receiving Data — OnRecive Event
PacketRequest — if the packet was fragmented, TerbinMemoryHelper.TryGetMemoryStream has already reassembled the payload before the event fires.
Return an InfoResponse? from the handler. A non-null return value is automatically dispatched back to the sender via Reply().
Accepting Additional Clients — OnNewClientConnect Event
TerbinCommunicator instance for the next client.
Replying and Advanced Control
Reply(InfoResponse)
IdRequest, Status, ActionMethod, and Payload from the provided InfoResponse. Called automatically when OnRecive returns a non-null value, but also available for deferred reply scenarios.
GiveResponse(PacketRequest)
Communicate() awaiter by matching pCapsule.Head.IdRequest against the _pendingRequests dictionary. Use this in advanced scenarios where you want to deliver a response outside the normal OnRecive path.
GiveProlong(ushort)
Communicate() call identified by pIdRequest. This prevents a CodeStatus.OverMaximumTime result when a long-running operation needs more time. The timer is reset to another full MaximumResponseTime interval.
Static Pipe Factories
- Server — bidirectional (
PipeDirection.In | PipeDirection.Out),MaxAllowedServerInstances,Bytetransmission mode, async options. - Client — bidirectional (
PipeDirection.InOut), async options, connecting to"."(local machine).
TerbinCommunicator.NewTerbinPipe and TerbinCommunicator.NewClientTerbinPipe.
Full Setup Examples
Minimal Server
Minimal Client
IDisposable Cleanup
TerbinCommunicator implements IDisposable. Calling Dispose() releases the underlying PipeStream, the StreamReadStruct, and the StreamWriteStruct. Always dispose when shutting down to avoid handle leaks: