---
title: "HiveMQ MQTT C# Client (BETA)"
description: "Learn how to use HiveMQ MQTT Client for C# and .Net platform for fast and reliable IoT and IIoT development."
date: 2023-03-30
published: 2023-03-30
author: Peter Giacomo Lombardo
tags:
  - MQTT Client
source: https://www.hivemq.com/blog/mqtt-client-library-for-c-sharp-dot-net
---

# HiveMQ MQTT C# Client (BETA)

HiveMQ created the MQTT C# Client as part of our larger efforts to offer the MQTT community reliable, tested, performant, and maintained MQTT clients. No longer are you limited to choosing from anonymous third-party MQTT clients who aren’t maintained, updated, or supported. HiveMQ aims to provide the community with clients with a clear path for features, fixes, and support - critical requirements to assure your devices are always functioning at full potential and your business is running without issue.

## Introduction to the HiveMQ MQTT C# Client

The new MQTT client for C# is in BETA, open source (available [on Github](https://github.com/hivemq/hivemq-mqtt-client-dotnet)), and licensed under the permissive Apache 2.0 License. We’re proud to open source this project for transparency and to welcome community input or contributions. The client currently features full [MQTT 5.0](/mqtt/mqtt-5) support and aims to be compatible with all major [MQTT brokers ](/blog/mqtt-brokers-beginners-guide)- regardless of vendor. Notable features of the client are an extensive event system that allows you to hook into any client functionality, from message handling down to packet delivery. As a feature of MQTT 5.0, it also supports back pressure handling to manage the load on your devices by communicating throughput limits. TLS, basic authentication and all [Quality of Service (QoS) levels](/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels) are supported - and more is to come. As this client matures, this post will be updated to reflect the latest changes and additions.

## Key Features of the HiveMQ C# Client

## How to Use the HiveMQ MQTT C# Client?

### Installation of HiveMQ MQTT C# Client

The HiveMQ MQTT C# Client is available as a Nuget package [hosted on NuGet.org](https://www.nuget.org/packages/HiveMQtt). To install:

### Creating the Client

The HiveMQ MQTT C# Client can be instantiated with smart defaults as simply as:

Instantiating the client with default settings as in the previous example assumes an MQTT broker on localhost:1883. But if you need to override that address, there is the *HiveMQClientOptions* class:

Passing in the *HiveMQClientOptions* structure, you can customize client settings and behavior. This class has many options available; see all the options available.

### Connecting with Authentication

This example shows how to provide simple authentication credentials:

### Connecting with An After Event

You can hook into the *AfterConnect* event to take any action as follows. Similar events exist for *Before/AfterSubscribe*, *OnMessageReceived*, *OnDisconnectReceived* and many more.

### Publish

In order to build and execute a publish, you would use code similar to the below:

There are variations on Publish that allow you to control how and what is published. See the available calls and MQTT5PublishMessage.

### Subscribe

When creating a subscription, you provide an event callback handler which is used for each incoming message via the *OnMessageReceived* event:

See also: HiveMQClient events

### Unsubscribe

To unsubscribe from a topic, simply call *UnsubscribeAsync* with the topic to unsubscribe from

If you want to view your existing subscriptions, they are always stored in *client.Subscriptions*.

### Disconnect

Just call *client.DisconnectAsync()* on the client object created previously.

### SSL / TLS

In order to use SSL / TLS for connecting to the broker, you simply specify its usage while building the client:

## References & See Also

### The HiveMQtt Client for C# on .NET

- The source code on Github: [github.com/hivemq/hivemq-mqtt-client-dotnet](http://github.com/hivemq/hivemq-mqtt-client-dotnet)
- The HiveMQtt NuGet Package: [nuget.org/packages/HiveMQtt](https://www.nuget.org/packages/HiveMQtt)

### HiveMQ Support & Community

- HiveMQ Community Forum: community.hivemq.com

## Summary

This is just the beginning of the story for HiveMQ and C#. We welcome you to try out the new client, browse the source code and contact us if you have any issues, comments or questions.

You can reach out to us on Github or in our [Community Forum](https://community.hivemq.com/).

Check out[ HiveMQ MQTT Client libraries and other featured MQTT client libraries.](/mqtt/mqtt-client-library-encyclopedia)
