This project is read-only.

IClient

This document explains the intent, thinking and code in the IClient interface

NetworkingLibrary-InitialRelease-IClient.png
(Above: Code overview of IClient)

IClient interface is to be implemented by all client classes. It provides a standard base from which all client classes can derive will allow easier and consistent use of the library.

IClient offers the very basic level of information that all clients should provide:

Properties:
  • BufferSize : The size of the read/write buffers the client is using. This will allow configuration for different client's and machine's memory capacities. It does not actually affect the amount of data written/read with each message sent, only the maximum amount of data to handle for any one receive operation. Note: multiple receive operations may occur simultaneously. Default value is 1,000,000 meaning 1,000,000 bytes maximum.
  • Connected : Whether the client is connected.
  • ID : The unique identifier that identifies this client. This should be used as a dictionary key when storing clients so that they can be distinguished. This is also helpful for async return methods as it allows easy identification of clients. Automatically set to Guid.NewGuid() on creation.
  • Terminating : Whether the client is terminating or has terminated. This includes closing any open connections and disposing/releasing of objects/resources. Start may be recalled depending upon implementation, this is not like IServer implementations.

Methods:
  • Connect : Initliases client then : Connects the client in the relevant way (depending upon protocol). Calls Start().
  • Disconnect : Disconnects the client in the relevant way (depending upon protocol). Calls Stop(). Finally disposes of objects and releases resources.
  • Start (+1 overloads) : There are two start methods for sending byte array data and MessageObjects. Byte array data gets wrapped in a DataMessage MessageObject object and sent, MessageObjects are sent as is.
    • Send(bye[] TheBuffer) : Calls Send(MessageObject TheObject).
    • Send(MessageObject TheMessage) : Actually sends the message object.
  • Start : Starts the client listening for data. Can only be called if Connected. Cannot be called after calling Disconnect without reinitialising (usde Connect method).
  • Stop : Stops the client listening for data. Can be called regardless.

Events:
  • OnConnect : Fired when the client successfully connects (depends upon protocol).
  • OnDisconnect : Fired when the client disconnects (depends upon protocol). Should be fired when Disconnect is called or if connection is lost/closed by the server.
  • OnError : Fired when any and all errors occur.
  • OnMessageReceived : Fired when a message is received and before default processing occurs. This allows the PreventDefault property of the event args to be set and this should be tested before default processing. Default procesing should not occur if this is set to true. This allows sub classes to extend functionality easily and without hinderence.

Last edited Dec 15, 2011 at 1:30 PM by EdwardNutting, version 7

Comments

No comments yet.