I'm trying to use "MQTTnet" in a Xamarin application. It connects fine but when I try to publish anything, well, it publishs but after about 5 seconds it throw the following exception
MQTTnet.Exceptions.MqttCommunicationTimedOutException
I'm not quite sure about what's happening there, the message is received successfully by the server
Server auth xmr/47cd7021-0f32-4cd4-b549-e8ebce2df612 from 192.168.1.8
Client xmr/47cd7021-0f32-4cd4-b549-e8ebce2df612 connected
Total connections: 3
$SYS/POezxDu/new/clients xmr/47cd7021-0f32-4cd4-b549-e8ebce2df612
hello/world hey
Client xmr/47cd7021-0f32-4cd4-b549-e8ebce2df612 disconnected
Total connections: 2
$SYS/POezxDu/disconnect/clients xmr/47cd7021-0f32-4cd4-b549-e8ebce2df612
Below is the code:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Options;
using System.Threading;
namespace MQTTXamarin
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Login : ContentPage
{
public Login()
{
InitializeComponent();
}
private void Btn_Login_Clicked(object sender, EventArgs e)
{
MqttConnect();
}
/* MQTT */
readonly IMqttClient client = new MqttFactory().CreateMqttClient();
private async void MqttConnect()
{
var options = new MqttClientOptionsBuilder()
.WithClientId("xmr/" + Guid.NewGuid().ToString())
.WithTcpServer("192.168.1.200", 1883)
.WithCredentials("DyPFunIOcljUT51i", "K1YMeKkvrK6yMvm7IlHadBA6JDBKzPGc")
.Build();
await client.ConnectAsync(options, CancellationToken.None);
var message = new MqttApplicationMessageBuilder()
.WithTopic("hello/world")
.WithPayload("hey")
.WithExactlyOnceQoS()
.Build();
await client.PublishAsync(message, CancellationToken.None);
}
}
}
Am I doing something wrong or is this buggy?