Class Host
The Host is what receives and responds to a Client's requests
This base Host has no actual implementation of handling connections, a "communication layer" needs to be used for that, such as TCPHost
Implements
Inherited Members
Namespace: VoltRpc.Communication
Assembly: VoltRpc.dll
Syntax
public abstract class Host : IDisposable
Constructors
| Edit this page View SourceHost(ILogger?, int)
Creates a new Host instance
Declaration
protected Host(ILogger? logger = null, int bufferSize = 8000)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | The ILogger to use |
int | bufferSize | The initial size of the buffers |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Will throw if the buffer size is less then 16 |
Fields
| Edit this page View SourceBufferSize
This size of the buffer
Declaration
protected readonly int BufferSize
Field Value
Type | Description |
---|---|
int |
DefaultBufferSize
The default size of the buffers
Declaration
public const int DefaultBufferSize = 8000
Field Value
Type | Description |
---|---|
int |
Logger
Logger
Declaration
protected readonly ILogger Logger
Field Value
Type | Description |
---|---|
ILogger |
Properties
| Edit this page View SourceConnectionCount
Count of number of connections
Declaration
public int ConnectionCount { get; protected set; }
Property Value
Type | Description |
---|---|
int |
HasDisposed
Has this object been disposed
Declaration
public bool HasDisposed { get; }
Property Value
Type | Description |
---|---|
bool |
HideStacktrace
Hides the stacktrace from the client when an Exception is thrown
Declaration
public bool HideStacktrace { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsRunning
Is the Host running?
Declaration
public bool IsRunning { get; protected set; }
Property Value
Type | Description |
---|---|
bool |
MaxConnectionsCount
What is the maximum amount of connections
Declaration
public int MaxConnectionsCount { get; set; }
Property Value
Type | Description |
---|---|
int |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if value is 0 or less |
TypeReaderWriterManager
The TypeReaderWriterManager for Host
Declaration
public TypeReaderWriterManager TypeReaderWriterManager { get; }
Property Value
Type | Description |
---|---|
TypeReaderWriterManager |
Methods
| Edit this page View SourceAddService(Type, object)
Adds a service to this Host
Declaration
public void AddService(Type serviceType, object serviceObject)
Parameters
Type | Name | Description |
---|---|---|
Type | serviceType | The Type of a service |
object | serviceObject | The actual service object itself |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the service has already been added |
ArgumentOutOfRangeException | Thrown if serviceType is not an interface |
AddService<T>(T)
Adds a service to this Host
Declaration
public void AddService<T>(T service) where T : class
Parameters
Type | Name | Description |
---|---|---|
T | service | The service object to add |
Type Parameters
Name | Description |
---|---|
T | The service type |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the service has already been added |
ArgumentOutOfRangeException | Thrown if T is not an interface |
CheckDispose()
Checks if the object has been disposed
Declaration
protected void CheckDispose()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException |
Dispose()
Destroys the Host instance
Declaration
public virtual void Dispose()
ProcessRequest(Stream, Stream)
Processes a request from a client
This override will automatically create the BufferedReader and BufferedWriter for you then call ProcessRequest(BufferedReader, BufferedWriter).
This is the preferred process request method to call.
Declaration
protected void ProcessRequest(Stream readStream, Stream writeStream)
Parameters
Type | Name | Description |
---|---|---|
Stream | readStream | The Stream to read from |
Stream | writeStream | The Stream to write to |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if either provide stream is null |
ArgumentOutOfRangeException | Thrown if we can't read or write to the respected stream |
ProcessRequest(BufferedReader, BufferedWriter)
Processes a request from a client
You should only call this if you need to provide a custom BufferedReader and/or BufferedWriter. For example you are using a Stream that needs Position.
Declaration
protected void ProcessRequest(BufferedReader reader, BufferedWriter writer)
Parameters
Type | Name | Description |
---|---|---|
BufferedReader | reader | The BufferedReader to read from |
BufferedWriter | writer | The BufferedWriter to write to |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if either buffer is null |
SetProtocolVersion(object?)
Sets what protocol version to use.
Set value to null to reset back to none.
Declaration
public void SetProtocolVersion(object? value)
Parameters
Type | Name | Description |
---|---|---|
object | value | Value can be any object you want, as long as the TypeReaderWriterManager has a TypeReadWriter<T> for it. |
Exceptions
Type | Condition |
---|---|
AlreadyRunningException | Thrown if the Host is already running |
NoTypeReaderWriterException | Thrown if the TypeReaderWriterManager doesn't have a TypeReadWriter<T> for the value Type. |
StartListening()
Starts listening for incoming requests
Declaration
public abstract void StartListening()
StartListeningAsync()
Starts listening for incoming requests
Declaration
public virtual Task StartListeningAsync()
Returns
Type | Description |
---|---|
Task |