Table of Contents

Class ModbusTcpServer

Namespace
FluentModbus
Assembly
FluentModbus.dll

A Modbus TCP server.

public class ModbusTcpServer : ModbusServer, IDisposable
Inheritance
ModbusTcpServer
Implements
Inherited Members

Constructors

ModbusTcpServer()

Creates a Modbus TCP server with support for holding registers (read and write, 16 bit), input registers (read-only, 16 bit), coils (read and write, 1 bit) and discete inputs (read-only, 1 bit).

public ModbusTcpServer()

ModbusTcpServer(ILogger)

Creates a Modbus TCP server with support for holding registers (read and write, 16 bit), input registers (read-only, 16 bit), coils (read and write, 1 bit) and discete inputs (read-only, 1 bit).

public ModbusTcpServer(ILogger logger)

Parameters

logger ILogger

A logger instance to provide runtime information.

ModbusTcpServer(ILogger, bool)

Creates a Modbus TCP server with support for holding registers (read and write, 16 bit), input registers (read-only, 16 bit), coils (read and write, 1 bit) and discete inputs (read-only, 1 bit).

public ModbusTcpServer(ILogger logger, bool isAsynchronous)

Parameters

logger ILogger

A logger instance to provide runtime information.

isAsynchronous bool

Enables or disables the asynchronous operation, where each client request is processed immediately using a locking mechanism. Use synchronuous operation to avoid locks in the hosting application. See the documentation for more details.

ModbusTcpServer(bool)

Creates a Modbus TCP server with support for holding registers (read and write, 16 bit), input registers (read-only, 16 bit), coils (read and write, 1 bit) and discete inputs (read-only, 1 bit).

public ModbusTcpServer(bool isAsynchronous)

Parameters

isAsynchronous bool

Enables or disables the asynchronous operation, where each client request is processed immediately using a locking mechanism. Use synchronuous operation to avoid locks in the hosting application. See the documentation for more details.

Properties

ConnectionCount

Gets the number of currently connected clients.

public int ConnectionCount { get; }

Property Value

int

ConnectionTimeout

Gets or sets the timeout for each client connection. When the client does not send any request within the specified period of time, the connection will be reset. Default is 1 minute.

public TimeSpan ConnectionTimeout { get; set; }

Property Value

TimeSpan

MaxConnections

Gets or sets the maximum number of concurrent client connections. A value of zero means there is no limit.

public int MaxConnections { get; set; }

Property Value

int

Methods

ProcessRequests()

Process incoming requests.

protected override void ProcessRequests()

Start()

Starts the server. It will listen on any IP address on port 502.

public void Start()

Start(ITcpClientProvider, bool)

Starts the server. It will accept all TCP clients provided by the provided ITcpClientProvider.

public void Start(ITcpClientProvider tcpClientProvider, bool leaveOpen = false)

Parameters

tcpClientProvider ITcpClientProvider

The TCP client provider.

leaveOpen bool

true to leave the TCP client provider open after the ModbusTcpServer object is stopped or disposed; otherwise, false.

Start(IPAddress)

Starts the server. It will listen on the provided ipAddress on port 502.

public void Start(IPAddress ipAddress)

Parameters

ipAddress IPAddress

Start(IPEndPoint)

Starts the server. It will listen on the provided localEndpoint.

public void Start(IPEndPoint localEndpoint)

Parameters

localEndpoint IPEndPoint

Start(TcpClient)

Starts the server. It will use only the provided TcpClient.

public void Start(TcpClient tcpClient)

Parameters

tcpClient TcpClient

The TCP client to communicate with.

Stop()

Stops the server and closes all open TCP connections.

public override void Stop()