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

Inheritance
Host
Implements
IDisposable
Namespace: VoltRpc.Communication
Assembly: VoltRpc.dll
Syntax
public abstract class Host : IDisposable

Constructors

| Edit this page View Source

Host(ILogger?, int)

Creates a new Host instance

Declaration
protected Host(ILogger? logger = null, int bufferSize = 8000)
Parameters
TypeNameDescription
ILoggerlogger

The ILogger to use

intbufferSize

The initial size of the buffers

Exceptions
TypeCondition
ArgumentOutOfRangeException

Will throw if the buffer size is less then 16

Fields

| Edit this page View Source

BufferSize

This size of the buffer

Declaration
protected readonly int BufferSize
Field Value
TypeDescription
int
| Edit this page View Source

DefaultBufferSize

The default size of the buffers

Declaration
public const int DefaultBufferSize = 8000
Field Value
TypeDescription
int
| Edit this page View Source

Logger

Logger

Declaration
protected readonly ILogger Logger
Field Value
TypeDescription
ILogger

Properties

| Edit this page View Source

ConnectionCount

Count of number of connections

Declaration
public int ConnectionCount { get; protected set; }
Property Value
TypeDescription
int
| Edit this page View Source

HasDisposed

Has this object been disposed

Declaration
public bool HasDisposed { get; }
Property Value
TypeDescription
bool
| Edit this page View Source

HideStacktrace

Hides the stacktrace from the client when an Exception is thrown

Declaration
public bool HideStacktrace { get; set; }
Property Value
TypeDescription
bool
| Edit this page View Source

IsRunning

Is the Host running?

Declaration
public bool IsRunning { get; protected set; }
Property Value
TypeDescription
bool
| Edit this page View Source

MaxConnectionsCount

What is the maximum amount of connections

Declaration
public int MaxConnectionsCount { get; set; }
Property Value
TypeDescription
int
Exceptions
TypeCondition
ArgumentOutOfRangeException

Thrown if value is 0 or less

| Edit this page View Source

TypeReaderWriterManager

Declaration
public TypeReaderWriterManager TypeReaderWriterManager { get; }
Property Value
TypeDescription
TypeReaderWriterManager

Methods

| Edit this page View Source

AddService(Type, object)

Adds a service to this Host

Declaration
public void AddService(Type serviceType, object serviceObject)
Parameters
TypeNameDescription
TypeserviceType

The Type of a service

objectserviceObject

The actual service object itself

Exceptions
TypeCondition
ArgumentException

Thrown if the service has already been added

ArgumentOutOfRangeException

Thrown if serviceType is not an interface

| Edit this page View Source

AddService<T>(T)

Adds a service to this Host

Declaration
public void AddService<T>(T service) where T : class
Parameters
TypeNameDescription
Tservice

The service object to add

Type Parameters
NameDescription
T

The service type

Exceptions
TypeCondition
ArgumentException

Thrown if the service has already been added

ArgumentOutOfRangeException

Thrown if T is not an interface

| Edit this page View Source

CheckDispose()

Checks if the object has been disposed

Declaration
protected void CheckDispose()
Exceptions
TypeCondition
ObjectDisposedException
| Edit this page View Source

Dispose()

Destroys the Host instance

Declaration
public virtual void Dispose()
| Edit this page View Source

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
TypeNameDescription
StreamreadStream

The Stream to read from

StreamwriteStream

The Stream to write to

Exceptions
TypeCondition
ArgumentNullException

Thrown if either provide stream is null

ArgumentOutOfRangeException

Thrown if we can't read or write to the respected stream

| Edit this page View Source

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
TypeNameDescription
BufferedReaderreader

The BufferedReader to read from

BufferedWriterwriter

The BufferedWriter to write to

Exceptions
TypeCondition
ArgumentNullException

Thrown if either buffer is null

| Edit this page View Source

SetProtocolVersion(object?)

Sets what protocol version to use.

Set value to null to reset back to none.

Declaration
public void SetProtocolVersion(object? value)
Parameters
TypeNameDescription
objectvalue

Value can be any object you want, as long as the TypeReaderWriterManager has a TypeReadWriter<T> for it.

Exceptions
TypeCondition
AlreadyRunningException

Thrown if the Host is already running

NoTypeReaderWriterException

Thrown if the TypeReaderWriterManager doesn't have a TypeReadWriter<T> for the value Type.

| Edit this page View Source

StartListening()

Starts listening for incoming requests

Declaration
public abstract void StartListening()
| Edit this page View Source

StartListeningAsync()

Starts listening for incoming requests

Declaration
public virtual Task StartListeningAsync()
Returns
TypeDescription
Task

Implements

IDisposable