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 in Terbin for inter-process communication over Windows named pipes. A single instance operates in either server or client mode and manages the full lifecycle of packet exchange: connection, background send/receive loops, request queuing, fragmentation, and timeout tracking. It implements IDisposable for safe resource cleanup.
Constructor
pIsServer is true, the instance immediately begins waiting for an incoming client connection asynchronously, starts background send/receive loops on connect, and fires OnNewClientConnect. When false, the pipe is a client that must call Connect() or TryConnect() manually.
true to operate as the server side of the named pipe; false for client mode.Cancellation token that stops background send and receive tasks when cancelled.
The name of the named pipe. Both ends must use the same name to connect.
Properties
IsServer
MaximumResponseTime
Communicate(). Defaults to TerbinProtocol.MAXIMUS_RESPONSE_TIME (8 seconds). If the timeout expires, Communicate() returns a PacketRequest whose Head.Status is CodeStatus.OverMaximumTime.
IsConnect
true when the underlying PipeStream reports it is currently connected. Read-only computed property backed directly by PipeStream.IsConnected.
Events
OnRecive
PacketRequest (with memory fragments already merged into Payload) and must return either:
- An
InfoResponsevalue —TerbinCommunicatorautomatically callsReply()with the returned value. null— suppresses the automatic reply. Use this when you have already replied viaGiveResponse(), or when the packet is fire-and-forget.
OnNewClientConnect
This event only fires on server-mode instances (
IsServer == true). Attaching it on a client has no effect.Connection Methods
TryConnect
true if a new connection was established; false if already connected, already a server, or connection failed.Connect
ConnectAsync() on the underlying NamedPipeClientStream and starts the background send and receive loops. Must be called once on client-mode instances before sending or receiving packets.
true if the connection succeeded; false if this instance is not a client pipe.Send Methods
Communicate
The action routing key identifying the handler to invoke on the other end.
The raw data body to transmit. Automatically fragmented if it exceeds
TerbinProtocol.MAX_PLD (0xFFF0 bytes).The status code stamped into the outgoing packet header.
Explicit request ID. When
null, a new ID is generated via MiniID.NewS.The response packet. Check
Head.Status for success (CodeStatus.Succes) or error codes such as CodeStatus.OverMaximumTime.Send
OnRecive.
The action routing key.
The data body to transmit.
The status code to embed in the packet header.
Explicit request ID. When
null, a new ID is generated via MiniID.NewS.null on success. Returns an error PacketRequest (e.g., CodeStatus.OverMaximunPacket) only if fragmentation fails.SendBytes
Send that accepts the payload as a params byte[] for inline byte literals.
The action routing key.
The status code to embed in the packet header.
Explicit request ID.
Individual bytes passed inline as variadic arguments.
null on success or a fragmentation error packet.Fragmentation Methods
These methods arepublic but are primarily called internally by the send pipeline. You may call them directly when building custom fragmentation logic.
HandleSendSigle
Send / Communicate when pPayload.Length <= TerbinProtocol.MAX_PLD.
The action routing key for the packet.
Data that fits within one packet.
The request ID to stamp into the header.
The status code for the header.
HandleSendFragment
TerbinProtocol.MAX_PLD by splitting them into chunks of TerbinProtocol.FRAGMENT_IN bytes (65,450 bytes, 0xFFAA), requesting a remote memory slot via SoliciteRequestMemory(), uploading each fragment via Load(), and then sending the final packet.
null on success. Returns an error packet if CheckExecution fails, memory cannot be allocated, or the packet count exceeds TerbinProtocol.FINAL_PACKET.SoliciteRequestMemory
CodeTerbinProtocol.Solicit packet to the remote end and awaits a memory slot ID in Payload[0]. Called internally before uploading fragments.
Response packet. On success,
Head.Status == CodeStatus.Succes and Payload[0] contains the allocated memory ID.Load
pPayload.Length >= TerbinProtocol.MAX_PLD.
The fragment’s position in the sequence (1-based,
ushort.MaxValue reserved for the final packet).The memory slot ID returned by
SoliciteRequestMemory().The fragment bytes. Must be smaller than
TerbinProtocol.MAX_PLD.The parent request ID. Auto-generated if
null.Always
true on success; throws on payload size violation.Response and Queue Methods
GiveResponse
Communicate() awaiter identified by pCapsule.Head.IdRequest. Use this from inside an OnRecive handler when you need to resolve the awaiter early (e.g., before an async sub-operation completes) and then return null to suppress the automatic reply.
The packet to deliver as the response. Its
Head.IdRequest must match the ID of a pending Communicate() call.GiveProlong
Communicate() call to another full MaximumResponseTime seconds. Call this from a long-running handler to prevent the caller from timing out.
The request ID whose timeout should be extended.
Reply
send pipeline using the fields of pInfo. This is called automatically when OnRecive returns a non-null InfoResponse, but you can call it directly for deferred replies.
The structured response to send.
pInfo.IdRequest must match the original request’s ID.addQueue
PacketRequest into the outbound send queue and signals the background send loop. Prefer Send / Communicate for normal usage.
A fully constructed packet ready to be transmitted.
Fragment order (
TerbinProtocol.ORDER_SINGLE for unfragmented, 1 for first fragment, ushort.MaxValue for last).The status code to stamp into the header.
The action routing key for the packet.
Memory slot identifier. Use
(byte)CodeTerbinMemory.NotAsign for non-fragmented packets.The raw bytes to carry as the packet payload.
The request ID to stamp into the header.
Static Pipe Helpers
These static members simplify named-pipe creation with Terbin’s recommended settings (asynchronous, bidirectional, byte-transmission mode).NewTerbinPipe
NamedPipeServerStream using default settings and the default pipe name "TerbinPipe". Each access creates a new stream.
NewClientTerbinPipe
NamedPipeClientStream using default settings and the default pipe name "TerbinPipe". Each access creates a new stream.
CreateServerPipe
NamedPipeServerStream with PipeDirection.InOut, MaxAllowedServerInstances, PipeTransmissionMode.Byte, and PipeOptions.Asynchronous.
The pipe name. Must match the name used by the client.
CreateClientPipe
NamedPipeClientStream targeting the local machine (.) with PipeDirection.InOut and PipeOptions.Asynchronous.
The pipe name. Must match the name used by the server.
IDisposable
TerbinCommunicator implements IDisposable. Always dispose the instance (or use a using block) to close the pipe and release stream resources.