FileClient Class

Represents a communication client based on FileStream.

Definition

Namespace: Gemstone.Communication
Assembly: Gemstone.Communication (in Gemstone.Communication.dll) Version: 1.0.110 -- Release Build+0c64c8391bfe7dd5190df3a4b323a05770415384
public class FileClient : ClientBase
Inheritance
Object    ClientBase    FileClient

Example

This example shows how to use FileClient for writing data to a file:
C#
using System;
using GSF.Communication;

class Program
{
    static FileClient s_client;

    static void Main(string[] args)
    {
        // Initialize the client.
        s_client = new FileClient(@"File=c:\File.txt");
        s_client.Initialize();
        // Register event handlers.
        s_client.ConnectionAttempt += s_client_ConnectionAttempt;
        s_client.ConnectionEstablished += s_client_ConnectionEstablished;
        s_client.ConnectionTerminated += s_client_ConnectionTerminated;
        s_client.SendDataComplete += s_client_SendDataComplete;
        // Connect the client.
        s_client.Connect();

        // Write user input to the file.
        string input;
        while (string.Compare(input = Console.ReadLine(), "Exit", true) != 0)
        {
            s_client.Send(input + Environment.NewLine);
        }

        // Disconnect the client on shutdown.
        s_client.Dispose();
    }

    static void s_client_ConnectionAttempt(object? sender, EventArgs e)
    {
        Console.WriteLine("Client is connecting to file.");
    }

    static void s_client_ConnectionEstablished(object? sender, EventArgs e)
    {
        Console.WriteLine("Client connected to file.");
    }

    static void s_client_ConnectionTerminated(object? sender, EventArgs e)
    {
        Console.WriteLine("Client disconnected from file.");
    }

    static void s_client_SendDataComplete(object? sender, EventArgs e)
    {
        Console.WriteLine(string.Format("Sent data - {0}", s_client.TextEncoding.GetString(s_client.Client.SendBuffer)));
    }
}
This example shows how to use FileClient for reading data to a file:
C#
using System;
using GSF;
using GSF.Communication;

class Program
{
    static FileClient s_client;

    static void Main(string[] args)
    {
        // Initialize the client.
        s_client = new FileClient(@"File=c:\File.txt");
        s_client.Initialize();
        // Register event handlers.
        s_client.ConnectionAttempt += s_client_ConnectionAttempt;
        s_client.ConnectionEstablished += s_client_ConnectionEstablished;
        s_client.ConnectionTerminated += s_client_ConnectionTerminated;
        s_client.ReceiveDataComplete += s_client_ReceiveDataComplete;
        // Connect the client.
        s_client.Connect();

        // Wait for client to read data.
        Console.ReadLine();

        // Disconnect the client on shutdown.
        s_client.Dispose();
    }

    static void s_client_ConnectionAttempt(object? sender, EventArgs e)
    {
        Console.WriteLine("Client is connecting to file.");
    }

    static void s_client_ConnectionEstablished(object? sender, EventArgs e)
    {
        Console.WriteLine("Client connected to file.");
    }

    static void s_client_ConnectionTerminated(object? sender, EventArgs e)
    {
        Console.WriteLine("Client disconnected from file.");
    }

    static void s_client_ReceiveDataComplete(object? sender, EventArgs<byte[], int> e)
    {
        Console.WriteLine(string.Format("Received data - {0}", s_client.TextEncoding.GetString(e.Argument1, 0, e.Argument2)));
    }
}

Constructors

FileClient Initializes a new instance of the FileClient class.
FileClient(String) Initializes a new instance of the FileClient class.

Properties

AtEOF Gets flags that determines if FileClient is positioned at the end of file.
AutoRepeat Gets or sets a boolean value that indicates whether receiving (reading) of data is to be repeated endlessly.
Client Gets the FileStream object for the FileClient.
ConnectionString Gets or sets the data required by the client to connect to the server.
(Inherited from ClientBase)
ConnectionTime Gets the Time for which the client has been connected to the server.
(Inherited from ClientBase)
CurrentState Gets the current ClientState.
(Inherited from ClientBase)
DisconnectAtEOF Gets or sets flag that determines if client should disconnect when end of file has been reached.
Enabled Gets or sets a boolean value that indicates whether the client is currently enabled.
(Inherited from ClientBase)
FileAccessMode Gets or sets the FileAccess value to be used when opening the file.
FileOpenMode Gets or sets the FileMode value to be used when opening the file.
FileShareMode Gets or set the FileShare value to be used when opening the file.
IsDisposed Gets a flag that indicates whether the object has been disposed.
(Inherited from ClientBase)
MaxConnectionAttempts Gets or sets the maximum number of times the client will attempt to connect to the server.
(Inherited from ClientBase)
Name Gets or sets the unique identifier of the server.
(Inherited from ClientBase)
ReadIndex Gets or sets current read index for received data buffer incremented at each Read(Byte, Int32, Int32) call.
(Inherited from ClientBase)
ReceiveBufferSize Gets or sets the size of the buffer used by the client for receiving data from the server.
(Inherited from ClientBase)
ReceiveInterval Gets or sets the number of milliseconds to pause before receiving (reading) the next available set of data.
ReceiveOnDemand Gets or sets a boolean value that indicates whether receiving (reading) of data will be initiated manually by calling ReadNextBuffer.
SendBufferSize Gets or sets the size of the buffer used by the client for sending data to the server.
(Inherited from ClientBase)
ServerIndex Gets the current server index, when multiple server end points are defined.
(Inherited from ClientBase)
ServerUri Gets the server URI of the FileClient.
(Overrides ClientBaseServerUri)
StartingOffset Gets or sets the starting point relative to the beginning of the file from where the data is to be received (read).
Statistics Gets the TransportStatistics for the client connection.
(Inherited from ClientBase)
Status Gets the descriptive status of the client.
(Inherited from ClientBase)
TextEncoding Gets or sets the Encoding to be used for the text sent to the server.
(Inherited from ClientBase)
TrackStatistics Determines whether the base class should track statistics.
(Inherited from ClientBase)
TransportProtocol Gets the TransportProtocol used by the client for the transportation of data with the server.
(Inherited from ClientBase)

Methods

Connect Connects the client to the server synchronously.
(Inherited from ClientBase)
ConnectAsync Connects the FileClient to the FileStream asynchronously.
(Overrides ClientBaseConnectAsync)
Disconnect Disconnects the FileClient from the FileStream.
(Overrides ClientBaseDisconnect)
Dispose Releases all the resources used by the ClientBase object.
(Inherited from ClientBase)
Dispose(Boolean) Releases the unmanaged resources used by the FileClient and optionally releases the managed resources.
(Overrides ClientBaseDispose(Boolean))
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
Initialize Initializes the client.
(Inherited from ClientBase)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
OnConnectionAttempt Raises the ConnectionAttempt event.
(Inherited from ClientBase)
OnConnectionEstablished Raises the ConnectionEstablished event.
(Inherited from ClientBase)
OnConnectionException Raises the ConnectionException event.
(Overrides ClientBaseOnConnectionException(Exception))
OnConnectionTerminated Raises the ConnectionTerminated event.
(Inherited from ClientBase)
OnEndOfFile Raises the EndOfFile event.
OnReceiveData Raises the ReceiveData event.
(Inherited from ClientBase)
OnReceiveDataComplete Raises the ReceiveDataComplete event.
(Inherited from ClientBase)
OnReceiveDataException Raises the ReceiveDataException event.
(Inherited from ClientBase)
OnSendDataComplete Raises the SendDataComplete event.
(Inherited from ClientBase)
OnSendDataException Raises the SendDataException event.
(Inherited from ClientBase)
OnSendDataStart Raises the SendDataStart event.
(Inherited from ClientBase)
Read Reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset.
(Overrides ClientBaseRead(Byte, Int32, Int32))
ReadNextBuffer Reads next data buffer from the FileStream.
RequestNextServerIndex Requests that the client attempt to move to the next ServerIndex.
(Inherited from ClientBase)
Send(Byte) Sends data to the server synchronously.
(Inherited from ClientBase)
Send(String) Sends data to the server synchronously.
(Inherited from ClientBase)
Send(Byte, Int32, Int32) Sends data to the server synchronously.
(Inherited from ClientBase)
SendAsync(Byte) Sends data to the server asynchronously.
(Inherited from ClientBase)
SendAsync(String) Sends data to the server asynchronously.
(Inherited from ClientBase)
SendAsync(Byte, Int32, Int32) Sends data to the server asynchronously.
(Inherited from ClientBase)
SendDataAsync Sends (writes) data to the file asynchronously.
(Overrides ClientBaseSendDataAsync(Byte, Int32, Int32))
ToStringReturns a string that represents the current object.
(Inherited from Object)
UpdateBytesReceived Updates the Statistics pertaining to bytes received.
(Inherited from ClientBase)
UpdateBytesSent Updates the Statistics pertaining to bytes sent.
(Inherited from ClientBase)
ValidateConnectionString Validates the specified connectionString.
(Overrides ClientBaseValidateConnectionString(String))

Events

ConnectionAttempt Occurs when client is attempting connection to the server.
(Inherited from ClientBase)
ConnectionEstablished Occurs when client connection to the server is established.
(Inherited from ClientBase)
ConnectionException Occurs when an Exception is encountered during connection attempt to the server.
(Inherited from ClientBase)
ConnectionTerminated Occurs when client connection to the server is terminated.
(Inherited from ClientBase)
Disposed Occurs when the ClientBase has been disposed.
(Inherited from ClientBase)
EndOfFile Occurs when the end of a file has been reached.
ReceiveData Occurs when unprocessed data has been received from the server.
(Inherited from ClientBase)
ReceiveDataComplete Occurs when data received from the server has been processed and is ready for consumption.
(Inherited from ClientBase)
ReceiveDataException Occurs when an Exception is encountered when receiving data from the server.
(Inherited from ClientBase)
SendDataComplete Occurs when the client has successfully sent data to the server.
(Inherited from ClientBase)
SendDataException Occurs when an Exception is encountered when sending data to the server.
(Inherited from ClientBase)
SendDataStart Occurs when the client begins sending data to the server.
(Inherited from ClientBase)

Fields

DefaultAutoRepeat Specifies the default value for the AutoRepeat property.
DefaultConnectionString Specifies the default value for the ConnectionString property.
DefaultDisconnectAtEOF Specifies the default value for the DisconnectAtEOF property.
DefaultFileAccessMode Specifies the default value for the FileAccessMode property.
DefaultFileOpenMode Specifies the default value for the FileOpenMode property.
DefaultFileShareMode Specifies the default value for the FileShareMode property.
DefaultReceiveInterval Specifies the default value for the ReceiveInterval property.
DefaultReceiveOnDemand Specifies the default value for the ReceiveOnDemand property.
DefaultStartingOffset Specifies the default value for the StartingOffset property.

See Also