0

I am trying to create a simple XMPP client in Xamarin using the Matrix.vNext package.

I have this basic code on my MainActivity:

using Android.App;
using Android.OS;
using Android.Widget;
using Matrix;
using System.Threading.Tasks;

namespace XmppAndroid
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
    public class MainActivity : Activity
    {
        private ToastHandler handler;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            var button = FindViewById<Button>(Resource.Id.button);
            button.Click += delegate
            {
                Task task = new Task(Connect);
                task.Start();
            };

            handler = new ToastHandler(this);
        }

        async void Connect()
        {
            var msg = new Android.OS.Message();

            msg.Data.PutString("message", "Connecting...");
            handler.SendMessage(msg);

            var client = new XmppClient
            {
                Username = "username",
                Password = "123456",
                XmppDomain = "domain.com"
            };

            await client.ConnectAsync();

            msg.Data.PutString("message", "Connected!");
            handler.SendMessage(msg);
        }
    }
}

ToastHandler is just a simple handler that creates a toast. I know for a fact it works, because the message "Connecting..." appears on screen. The second message, however, doesn't appear. It seems that the client refuses to connect.

Any idea how to fix it?

Jahanvi Kariya
  • 377
  • 3
  • 14
Oval
  • 37
  • 8
  • Have you stepped through this in the debugger? Have you checked for exceptions? Have you checked the console for helpful messages? Have you checked the logs that vNext provides? – Jason Dec 11 '19 at 13:01
  • MatriX vNext should work fine on Xamarin. There are some known issues with Mono that affect Tls. But in our forums you can find a solution to that: https://forum.ag-software.net/thread/2147-Matrix-vNext-in-Xamarin-Forms-DotNetty-Transport – Alex Dec 23 '19 at 13:06

0 Answers0