Sharp.Xmpp FCM上游消息

问题描述 投票:1回答:1

我正在使用Sharp.Xmpp通过FCM从Android设备接收上游消息。它很好地连接和“有时”我可以在我的应用服务器上接收从Android发送的消息,但比率为50%而Android设备提供了成功的onMessageSent事件。服务器端代码是:

try {
     using (var cl = new XmppClient("fcm-xmpp.googleapis.com", "Username", "Password", 5236, Sharp.Xmpp.Core.TLSMode.TLSSocket)) {

     // Setup any event handlers before connecting.
     cl.Message += OnNewMessage;

     // Connect and authenticate with the server.
     cl.Connect();

     SendPushNotification("Connected");

     cl.Close(); }
}
catch (InvalidOperationException ex) { SendPushNotification("Error Invalid: " + ex); }
catch (IOException ex) { SendPushNotification("Error IO: " + ex); }
catch (XmppException ex) { SendPushNotification("Error XMPP: " + ex); }
catch (NullReferenceException ex) { SendPushNotification("Error Null: " + ex); }

收到新消息的事件是

private void OnNewMessage(object sender, Sharp.Xmpp.Im.MessageEventArgs e) {
    SendPushNotification("Message from " + e.Jid + " " + e.Message.Body);
    div_View_Message.InnerHtml = "Message xyz " + e.Message.Body.ToString();
    //throw new NotImplementedException();
}

SendPushNotification(String str)是HTTP协议的下游消息。 Android设备会收到“已连接”的推送通知,但有时会收到“e.Message.Body”,而不是其他人。应该添加/删除什么?

Android将消息发送为

FirebaseMessaging.getInstance().send(new RemoteMessage.Builder("[email protected]")
            .setMessageId(Integer.toString(INT_VALUE)).addData("my_token", str).build());
android firebase sharp.xmpp
1个回答
0
投票

正如this问题的公认答案所述,XMPP必须始终保持开放。因此,基于Web的应用程序(在每秒几次请求之后关闭连接)切换到托管在本地服务器上的桌面应用程序,解决了这个问题。

此外,它添加setTtl(86400);用于消息发送确保onMessageSent调用。

© www.soinside.com 2019 - 2024. All rights reserved.