# Architecture Mrgada usess simple a server/client architecture. The main mrgada server is used for simple datetime synchronization between clients and authentication, while the collectors are in charge of synchronizing data between clients and PLCs. - Not yet implemented: public private key authentication ```{image} ../_static/images/Architecture.png ``` ## Collectors A Collector is the class that interacts with the plc. In case of s7, it reads bytes, parses those bytes, and handles writing to bytes, allowing for the same codebase for server and client SCADA applications. ### ServerCollector The ServerCollector class is a simple wraper for the TcpServer class. It allows for automatic client connection, overridable methods OnClientConnected OnDataRecieved, etc... #### Dependencies - `Serilog` - `SerilogTimings` - `System` - `System.Collections.Generic` - `System.Diagnostics` - `System.Net.Sockets` - `using System.Threading` ```Csharp ServerCollector ( string collectorName, int collectorPort, int connectTimeoutMilliseconds = 3000, int receiveBroadcastTimeout = 200 ) ``` ### ClientCollector The ClientCollector class is a simple wraper for the TcpClient class. It allows for automatic client connection, overridable methods OnClientConnected OnDataRecieved, etc... #### Dependencies - `Serilog` - `System.Collections.Generic` - `System.Text` - `System.Threading` #### Constructor ```Csharp ClientCollector ( string collectorName, int collectorPort, int connectTimeoutMilliseconds = 3000, int receiveBroadcastTimeout = 200 ) ``` - **collectorName** : `string` - The name of the collector, used for logging purpuses. - **serverPort** : `int` - The port number, the collector will be running on. - **connectHandlerTimeout** : `int` - Timeout for handling connection establishment (default 3000ms). - **receiveBroadcastTimeout** : `int` - Timeout for receiving broadcasts (default 200ms). #### Public variables ```Csharp public readonly bool Connected ``` ```Csharp public readonly bool Started ``` #### Virutal methods ```Csharp public virtual void OnReceive(byte[] data) ``` ```Csharp public virtual void OnConnect() ``` ```Csharp public virtual void OnDisconnect() ``` ```Csharp public virtual void OnStart() ``` ```Csharp public virtual void OnStop() ``` #### Methods ```Csharp public void AddToSendQueue(byte[] data) ```