OpenClient
Inherits: Disposable
Constructors
public OpenClient(string host, uint port)
openClient = OpenClient(host, port)
Creates an instance of OpenClient which is not connected yet
- host
- The host name of API endpoint
- port
- The host port number
Properties
public string Host { get; }
value = openClient.Host
The API endpoint host that the current client is connected to
public bool IsCompleted { get; private set; }
value = openClient.IsCompleted
openClient.IsCompleted = value
If client stream is completed without any error then it will return True, otherwise False
public bool IsTerminated { get; private set; }
value = openClient.IsTerminated
openClient.IsTerminated = value
If there was any error (exception) on client stream then this will return True, otherwise False
public uint Port { get; }
value = openClient.Port
The API host port that current client is connected to
Methods
public Task Connect(CancellationToken cancellationToken)
result = openClient.Connect(cancellationToken)
Connects to the API based on you specified method
Returns: Task
private Task ConnectTcp(CancellationToken cancellationToken)
result = openClient.ConnectTcp(cancellationToken)
Connects to API by using a TCP client
Returns: Task
protected override void DisposeManaged()
openClient.DisposeManaged()
Disposes the client, releases all used resources, and stops all running operations
private static int GetLength(byte[] lengthBytes)
result = OpenClient.GetLength(lengthBytes)
Returns the length of a received message without causing extra allocation
- lengthBytes
- The byte array of received length data
Returns: int
private void OnCompleted()
openClient.OnCompleted()
Completes each observer by calling their OnCompleted method
private void OnError(Exception exception)
openClient.OnError(exception)
Disposes the client and then calls each observer OnError after an exception thrown
- exception
- Exception
private Task ReadTcp(CancellationToken cancellationToken)
result = openClient.ReadTcp(cancellationToken)
This method will read the TCP stream for incoming messages
- cancellationToken
- The cancellation token that will be used on ReadAsync calls
Returns: Task
public Task SendMessage(ProtoMessage message, CancellationToken cancellationToken)
result = openClient.SendMessage(message, cancellationToken)
This method will insert your message on messages queue, it will not send the message instantly
- message
- Message
- cancellationToken
Returns: Task
public Task SendMessage<T>(T message, ProtoOAPayloadType payloadType, string clientMsgId, CancellationToken cancellationToken)
result = openClient.SendMessage(message, payloadType, clientMsgId, cancellationToken)
This method will insert your message on messages queue, it will not send the message instantly
- message
- Message
- payloadType
- Message Payload Type (ProtoOAPayloadType)
- clientMsgId
- The client message ID (optional)
- cancellationToken
Returns: Task
public Task SendMessage<T>(T message, string clientMsgId, CancellationToken cancellationToken)
result = openClient.SendMessage(message, clientMsgId, cancellationToken)
This method will insert your message on messages queue, it will not send the message instantly By using this overload of SendMessage method you avoid passing the message payload type and it gets the payload from message itself
- message
- Message
- clientMsgId
- The client message ID (optional)
- cancellationToken
Returns: Task
public Task SendMessage<T>(T message, ProtoPayloadType payloadType, string clientMsgId, CancellationToken cancellationToken)
result = openClient.SendMessage(message, payloadType, clientMsgId, cancellationToken)
This method will insert your message on messages queue, it will not send the message instantly
- message
- Message
- payloadType
- Message Payload Type (ProtoPayloadType)
- clientMsgId
- The client message ID (optional)
- cancellationToken
Returns: Task
private void ThrowObjectDisposedExceptionIfDisposed()
openClient.ThrowObjectDisposedExceptionIfDisposed()
Throws ObjectDisposedException if the client was disposed
private Task WriteTcp(byte[] messageByte, CancellationToken cancellationToken)
result = openClient.WriteTcp(messageByte, cancellationToken)
Writes the message bytes to TCP stream
- messageByte
- cancellationToken
- The cancellation token that will be used on calling stream methods
Returns: Task
Events
public event Action<ProtoMessage> MessageReceived
openClient.MessageReceived += handler
This event will be triggered when a message is received from the API