Table of Contents

Class MqttNetworkChannel

Namespace
nanoFramework.M2Mqtt
Assembly
nanoFramework.M2Mqtt.dll

Channel to communicate over the network

public class MqttNetworkChannel : IMqttNetworkChannel
Inheritance
MqttNetworkChannel
Implements
Inherited Members
Extension Methods

Constructors

MqttNetworkChannel(Socket)

Constructor

public MqttNetworkChannel(Socket socket)

Parameters

socket Socket

Socket opened with the client

MqttNetworkChannel(Socket, bool, X509Certificate, MqttSslProtocols)

Constructor

public MqttNetworkChannel(Socket socket, bool secure, X509Certificate serverCert, MqttSslProtocols sslProtocol)

Parameters

socket Socket

Socket opened with the client

secure bool

Secure connection (SSL/TLS)

serverCert X509Certificate

Server X509 certificate for secure connection

sslProtocol MqttSslProtocols

SSL/TLS protocol version

MqttNetworkChannel(string, int)

Constructor

public MqttNetworkChannel(string remoteHostName, int remotePort)

Parameters

remoteHostName string

Remote Host name

remotePort int

Remote port

MqttNetworkChannel(string, int, bool, X509Certificate, X509Certificate, MqttSslProtocols)

Constructor

public MqttNetworkChannel(string remoteHostName, int remotePort, bool secure, X509Certificate caCert, X509Certificate clientCert, MqttSslProtocols sslProtocol)

Parameters

remoteHostName string

Remote Host name

remotePort int

Remote port

secure bool

Using SSL

caCert X509Certificate

CA certificate

clientCert X509Certificate

Client certificate

sslProtocol MqttSslProtocols

SSL/TLS protocol version

Properties

DataAvailable

Data available on the channel

public bool DataAvailable { get; }

Property Value

bool

RemoteHostName

Remote host name

public string RemoteHostName { get; }

Property Value

string

RemoteIpAddress

Remote IP address

public IPAddress RemoteIpAddress { get; }

Property Value

IPAddress

RemotePort

Remote port

public int RemotePort { get; }

Property Value

int

ValidateServerCertificate

True to check the server certificate when connecting using TLS. Disabling this property will bypass the validation of the server root CA certificate. Using the library this way it's unsecured and, therefore, not recommended.

public bool ValidateServerCertificate { get; set; }

Property Value

bool

Methods

Accept()

Accept connection from a remote client

public void Accept()

Close()

Close the network channel

public void Close()

Connect()

Connect to remote server

public void Connect()

Receive(byte[])

Receive data from the network

public int Receive(byte[] buffer)

Parameters

buffer byte[]

Data buffer for receiving data

Returns

int

Number of bytes received

Receive(byte[], int)

Receive data from the network channel with a specified timeout

public int Receive(byte[] buffer, int timeout)

Parameters

buffer byte[]

Data buffer for receiving data

timeout int

Timeout on receiving (in milliseconds)

Returns

int

Number of bytes received

Send(byte[])

Send data on the network channel

public int Send(byte[] buffer)

Parameters

buffer byte[]

Data buffer to send

Returns

int

Number of byte sent