Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Send message/Closing connection not happening until I receive a message
Page:  1  2  next
sathyajithr.dev #1
Member since Jul 2020 · 8 posts
Group memberships: Members
Show profile · Link to this post
Subject: Matrix Xmpp: Xamarin Forms issue while sending message or closing connection
I am implementing chat functionality in a Xamarin forms application. Connection to the chat server, user subscription, presence subscription and even message receiving is working smoothly. But while trying to send a message or disconnect a connection, the method execution stuck and it won't be successful. Once a message is received (Sending from Gajim windows client) the execution continues from xmppClient.Send()/xmppClient.Close() calls.  I tried it from both Android and iOS applications and the behavior is the same. I also tested the sample app (https://gitlab.com/matrix-xmpp/samples/-/tree/master/cshar…)  and its the same behavior, method execution stuck in xmppClient.Close() and only executes further once a message is received.

I am having latest xamarin SDKs

Xamarin iOS - 13.18.3.2
Xamarin Android - 10.3.1.4

Another thing I noticed is that the same code I written works when building from another machine which is having lower version of Xamarin iOS SDK, sending message was working fine. But having issues to send message from Android app which is built from that machine. The Xamarin iOS SDK version in that machine is

Xamarin iOS - 13.6.0.12

Is there any compatibility issue with latest Xamarin SDKs? Please advise how to resolve this issue.

Below are the logs.
PS: OnSendMessage it would log as sending message, but it would get delivered and method execution continues only when a message is received in my app.

14:35:45.844 D/ChatService: XmppOnSendMessage:<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="server.address.com" version="1.0" >:
14:35:46.142 D/ChatService: XmppOnXmlReceiveMessage:<stream:stream xmlns:stream="http://etherx.jabber.org/streams" id="5041239102440826853" version="1.0" xml:lang="en" from="server.address.com" xmlns="jabber:client" >:
14:35:46.157 D/ChatService: XmppOnXmlReceiveMessage:<stream:features xmlns:stream="http://etherx.jabber.org/streams">
14:35:46.157 D/ChatService:   <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
14:35:46.157 D/ChatService:     <required />
14:35:46.157 D/ChatService:   </starttls>
14:35:46.157 D/ChatService: </stream:features>:
14:35:46.167 D/ChatService: XmppOnSendMessage:<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />:
14:35:46.428 D/ChatService: XmppOnXmlReceiveMessage:<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />:
14:35:47.268 D/ChatService: XmppOnSendMessage:<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="server.address.com" version="1.0" >:
14:35:47.547 D/ChatService: XmppOnXmlReceiveMessage:<stream:stream xmlns:stream="http://etherx.jabber.org/streams" id="18057076616736662190" version="1.0" xml:lang="en" from="server.address.com" xmlns="jabber:client" >:
14:35:47.550 D/ChatService: XmppOnXmlReceiveMessage:<stream:features xmlns:stream="http://etherx.jabber.org/streams">
14:35:47.550 D/ChatService:   <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
14:35:47.550 D/ChatService:     <mechanism>DIGEST-MD5</mechanism>
14:35:47.550 D/ChatService:     <mechanism>PLAIN</mechanism>
14:35:47.550 D/ChatService:     <mechanism>SCRAM-SHA-1</mechanism>
14:35:47.550 D/ChatService:     <mechanism>X-OAUTH2</mechanism>
14:35:47.550 D/ChatService:   </mechanisms>
14:35:47.550 D/ChatService:   <register xmlns="http://jabber.org/features/iq-register" />
14:35:47.550 D/ChatService: </stream:features>:
14:35:47.550 D/ChatService: XmppOnStreamFeatures: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
14:35:47.550 D/ChatService:   <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
14:35:47.550 D/ChatService:     <mechanism>DIGEST-MD5</mechanism>
14:35:47.550 D/ChatService:     <mechanism>PLAIN</mechanism>
14:35:47.550 D/ChatService:     <mechanism>SCRAM-SHA-1</mechanism>
14:35:47.550 D/ChatService:     <mechanism>X-OAUTH2</mechanism>
14:35:47.550 D/ChatService:   </mechanisms>
14:35:47.550 D/ChatService:   <register xmlns="http://jabber.org/features/iq-register" />
14:35:47.550 D/ChatService: </stream:features>
14:35:47.572 D/ChatService: XmppOnSendMessage:<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">XXXXX</auth>:
14:35:47.837 D/ChatService: XmppOnXmlReceiveMessage:<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />:
14:35:47.843 D/ChatService: xmppClient_OnLogin: Matrix.EventArgs
14:35:47.844 D/ChatService: XmppOnSendMessage:<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="server.address.com" version="1.0" >:
14:35:48.107 D/ChatService: XmppOnXmlReceiveMessage:<stream:stream xmlns:stream="http://etherx.jabber.org/streams" id="8809054255882851270" version="1.0" xml:lang="en" from="server.address.com" xmlns="jabber:client" >:
14:35:48.112 D/ChatService: XmppOnXmlReceiveMessage:<stream:features xmlns:stream="http://etherx.jabber.org/streams">
14:35:48.112 D/ChatService:   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" />
14:35:48.112 D/ChatService:   <session xmlns="urn:ietf:params:xml:ns:xmpp-session">
14:35:48.112 D/ChatService:     <optional />
14:35:48.112 D/ChatService:   </session>
14:35:48.112 D/ChatService:   <c ver="NqMDrgCx03HLh3URMusgDnNsR30=" node="http://www.process-one.net/en/ejabberd/" hash="sha-1" xmlns="http://jabber.org/protocol/caps" />
14:35:48.112 D/ChatService:   <sm xmlns="urn:xmpp:sm:2" />
14:35:48.112 D/ChatService:   <sm xmlns="urn:xmpp:sm:3" />
14:35:48.112 D/ChatService:   <ver xmlns="urn:xmpp:features:rosterver" />
14:35:48.112 D/ChatService:   <csi xmlns="urn:xmpp:csi:0" />
14:35:48.112 D/ChatService: </stream:features>:
14:35:48.127 D/ChatService: XmppOnSendMessage:<iq id="MX_1" type="set" xmlns="jabber:client">
14:35:48.127 D/ChatService:   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
14:35:48.127 D/ChatService:     <resource>MatriX-for-Android</resource>
14:35:48.127 D/ChatService:   </bind>
14:35:48.127 D/ChatService: </iq>:
14:35:48.397 D/ChatService: XmppOnXmlReceiveMessage:<iq type="result" id="MX_1" xmlns="jabber:client">
14:35:48.397 D/ChatService:   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
14:35:48.397 D/ChatService:     <jid>jack@server.address.com/MatriX-for-Android</jid>
14:35:48.397 D/ChatService:   </bind>
14:35:48.397 D/ChatService: </iq>:
14:35:48.411 D/ChatService: XmppOnSendMessage:<iq to="server.address.com" type="set" id="sess_1">
14:35:48.411 D/ChatService:   <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
14:35:48.411 D/ChatService: </iq>:
14:35:48.415 D/ChatService: XmppOnSendMessage:<enable resume="true" xmlns="urn:xmpp:sm:3" />:
14:35:48.423 D/ChatService: XmppOnSendMessage:<iq id="MX_2" type="get" xmlns="jabber:client">
14:35:48.423 D/ChatService:   <query xmlns="jabber:iq:roster" />
14:35:48.423 D/ChatService: </iq>:
14:35:48.670 D/ChatService: XmppOnXmlReceiveMessage:<iq xml:lang="en" to="jack@server.address.com/MatriX-for-Android" from="server.address.com" type="result" id="sess_1" xmlns="jabber:client" />:
14:35:48.670 D/ChatService: <<<<<Session established>>>>>
14:35:48.673 D/ChatService: XmppOnSendMessage:<presence type="subscribe" to="harry@server.address.com" id="MX_3" xmlns="jabber:client" />:
14:35:48.673 D/ChatService: SubscribeUser sent:harry@server.address.com
14:35:48.675 D/ChatService: XmppOnXmlReceiveMessage:<enabled resume="true" max="300" id="g2gCbQAAABJNYXRyaVgtZm9yLUFuZHJvaWRoA2IAAAY7YgAI365iAAABkA==" xmlns="urn:xmpp:sm:3" />:
14:35:48.688 D/ChatService: XmppOnXmlReceiveMessage:<iq xml:lang="en" to="jack@server.address.com/MatriX-for-Android" from="jack@server.address.com" type="result" id="MX_2" xmlns="jabber:client">
14:35:48.688 D/ChatService:   <query xmlns="jabber:iq:roster">
14:35:48.688 D/ChatService:     <item subscription="both" jid="harry@server.address.com" />
14:35:48.688 D/ChatService:   </query>
14:35:48.688 D/ChatService: </iq>:
14:35:48.694 D/ChatService: XmppOnSendMessage:<presence xmlns="jabber:client">
14:35:48.694 D/ChatService:   <show>chat</show>
14:35:48.694 D/ChatService:   <status></status>
14:35:48.694 D/ChatService:   <priority>0</priority>
14:35:48.694 D/ChatService: </presence>:
14:35:48.697 D/ChatService: XmppOnXmlReceiveMessage:<r xmlns="urn:xmpp:sm:3" />:
14:35:48.700 D/ChatService: XmppOnSendMessage:<a h="1" xmlns="urn:xmpp:sm:3" />:
14:35:48.957 D/ChatService: XmppOnXmlReceiveMessage:<presence xml:lang="en" to="jack@server.address.com/MatriX-for-Android" from="jack@server.address.com/MatriX-for-Android" xmlns="jabber:client">
14:35:48.957 D/ChatService:   <x xmlns="vcard-temp:x:update" />
14:35:48.957 D/ChatService:   <priority>0</priority>
14:35:48.957 D/ChatService:   <show>chat</show>
14:35:48.957 D/ChatService:   <status />
14:35:48.957 D/ChatService: </presence>:
14:35:48.966 D/ChatService: XmppOnXmlReceiveMessage:<r xmlns="urn:xmpp:sm:3" />:
14:35:48.966 D/ChatService: XmppOnSendMessage:<a h="2" xmlns="urn:xmpp:sm:3" />:
14:35:55.333 D/ChatService: XmppOnSendMessage:<message to="harry@server.address.com" from="jack@server.address.com/MatriX-for-Android" type="chat" id="4b7afe63-3f6c-4191-8270-303e664a6eb7" xml:lang="en" xmlns="jabber:client">
14:35:55.333 D/ChatService:   <body>Thank you! I am over it now.</body>
14:35:55.333 D/ChatService:   <active xmlns="http://jabber.org/protocol/chatstates" />
14:35:55.333 D/ChatService:   <origin-id id="4b7afe63-3f6c-4191-8270-303e664a6eb7" xmlns="urn:xmpp:sid:0" />
14:35:55.333 D/ChatService: </message>:
This post was edited 2 times, last on 2020-07-30, 23:35 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

can you provide the code snippets which you are using to send the message?
It looks like MatriX is establishing the connection to your server fine, and internally MatriX is sending the stanzas to build up the connection in exactly the same way.

Would it be possible that there is some deadlock? Do you know if Xamarin changes anything in regards to threading?
Have you treid to send messages in a new thread for a test?

You are using Stream Management. Have you tried to disable it for a test?

Which MatriX versions and builds are you using on iOS and Android?

Alex
sathyajithr.dev #3
Member since Jul 2020 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hello Alex,

Thank you for the response.

Yes, if the send message method is called from UI thread app is getting stuck. So I am calling it from a new thread and that thread execution stuck and it only continues when receives a message from server.
Yes, we had also tried disabling stream management and the behavior is the same.
And it is not issue with only sending messages, for xmppClient close operation also we are getting the same behavior. If we try to close the connection, then also thread execution gets stuck and disconnection would complete as soon as we receive a message from server.

I am not sure whether Xamarin changed anything related to threading.

We are using the latest Matrix XMPP library versions available in NuGet

MatriX.Xamarin.Android - 2.1.0.3
MatriX.Xamarin.iOS - 2.1.0.6

Below is the send message code used

  1. Message xmppMessage = new Message()
  2.                 {
  3.                     To = ToChatAddress,
  4.                     From = FromChatAddress,
  5.                     Body = messageBody,
  6.                     Type = Matrix.Xmpp.MessageType.Chat,
  7.                     Subject = SubjectMessageData,
  8.                     Id = chatData.MessageId,
  9.                     Chatstate = Matrix.Xmpp.Chatstates.Chatstate.Active,
  10.                     XmlLanguage = "en"
  11.                 };
  12.  
  13. _xmppClient.Send(xmppMessage);
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Can you try to disable TLS for a test?
In some Mono TLS implementations we have seen similar issues.

Alex
sathyajithr.dev #5
Member since Jul 2020 · 8 posts
Group memberships: Members
Show profile · Link to this post
TLS is required by the server. When StartTls is disabled it is throwing TlsRequiredException and unable to connect to chat server.

Matrix.TlsRequiredException: TLS is required by the server, but not supported or disabled by the XmppClient.
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You have to make TLS optional on your server for testing this.
Or use another server where it is optional.

Alex
sathyajithr.dev #7
Member since Jul 2020 · 8 posts
Group memberships: Members
Show profile · Link to this post
We tried to disable the TLS in server but not able to disable it. After changing some settings still it asks for TLS. Since anyway in production TLS needs to be enabled, could you please advise whether there is anything else we can do.
Avatar
Alex #8
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Can't you install a server on your local machine for tetsing this? Either locally on the OS or in Docker?
Or change the configuration of one your dev or staging server?

Alex
sathyajithr.dev #9
Member since Jul 2020 · 8 posts
Group memberships: Members
Show profile · Link to this post
I downgraded the visual studio from 2019 to 2017 and now my Xamarin Android SDK version is 9.1.7.0. Now the same code works with TLS in Android devices also. So it should be compatibility issue with latest Xamarin SDKs. Could you please advise how can we use the library with latest Xamarin Form SDKs.
Avatar
Alex #10
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

did you make the tests I suggested with TLS and without TLS?
Or did you only try to upgrade and downgrade the Xamarin version?

If its a TLS issue in a certain Xamarin build then there is not much we can do. In this case we would have to report a bug at Xamarin/Microsoft and wait until they fix it.

To be honest, I have not tried it myself with the very latest Xamarin version yet.
I can do so if you write a very simple test case which helps us to reproduce your problem.

Alex
This post was edited on 2020-08-06, 10:56 by Alex.
sathyajithr.dev #11
Member since Jul 2020 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hi,

We were not able to test without TLS disabled. After changing the TLS settings when tried to connect to server, it was throwing TLS exception.
The Xamarin sample app provided in this link is having the same issue https://gitlab.com/matrix-xmpp/samples/-/tree/master/cshar….

Yes, we are existing customer. We have purchased the license for Xamarin Android and iOS Matrix XMPP SDKs, if you want we can provide the invoice details. We have to create the build using latest Xamarin SDKs else app store might reject our app as old Xamarin SDKs will be using deprecated components. So we would like to make this library work with latest Xamarin SDKs. Could you please advise how we can make it work.
Avatar
Alex #12
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I was able to reproduce your problem on Android.
My assumption seems to be correct and it seems to be related to an older SslStream issue in Mono.
When I connect using Tls blocks on this call:

  1. networkStream.BeginWrite(...);

a BeginWrite call should always return immediately.

I made TLS optional on one if our server. When I disable TLS it works fine.
When you want then I can create you 1 or 2 test accounts on this server to verify.

I assume that with the latest Xamarin builds they introduced now the Mono SslStream issues which other people were facing before with netStandard code on Xamarin. See also this thread which described the issues:
https://forum.ag-software.net/thread/2147-Matrix-vNext-in-…


I think this is a bug in Xamarin and needs to be addressed by Microsoft. I will do some more research on this and eventually open an issue at Xamarin.

Alex
This post was edited on 2020-08-04, 15:08 by Alex.
Avatar
Alex #13
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
It looks like Microsoft provided a fix to this according to this issue on GitHub:
https://github.com/mono/mono/issues/18865

Could you try with the pre release versions mentioned there?
sathyajithr.dev #14
Member since Jul 2020 · 8 posts
Group memberships: Members
Show profile · Link to this post
Hi,

Yes, tried by upgrading the visual studio with latest preview version and the sending chat functionality is working fine with latest Xamarin Android SDK. Thank you for your assistance.
I would like to hear your opinion on using that preview version to develop the app. Is it advisable to use the preview version of Visual studio, will the Xamarin SDKs stable to use?
Avatar
Alex #15
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I use Preview version of Visual Studio most of the time and never had an issue.
This also seems the only workaround for now until they release new final Xamarin builds which includes this fix.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next