3

Smack APIを使用してXMPPサーバーに接続するアプリケーションをAndroidで開発しました。このアプリケーションでは、ユーザーサインイン情報(ユーザー名とパスワード)をハードコーディングします。

xmpp.login( "admin"、 "tigase");

別のユーザーからパケットを受け取ります

PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class)、new FromContainsFilter( "ameya @ mwbn43-1"));

現在、2つの異なるAndroidデバイスで同じアプリを実行すると、1つのデバイスが他のデバイスのクレデンシャルを上書きするため、データを送信しようとすると、そのうちの1つだけがデータを取得するという問題に直面しています。通常のGoogleチャットでは、ユーザーは2つの異なる場所から同じアカウントにログインし、両方の場所で同時にメッセージを受信できます。

誰かが問題の可能性を教えてもらえますか?それはSmack APIと関係がありますか?

ありがとう、

あめや

4

3 に答える 3

8

あなたがしなければならないことはあなたがログインするときに別のリソースを設定することです

xmpp.login("admin", "tigase", "a random string here");

リソースは、概念的にはTCPポートに似ています。このリンクを参照してください。リソース文字列を使用してデバイスを区別する方法は、同じアカウントにログインします。デスクトップでは、リソースはたとえばAndroidでは「desktop」と「android」になります。ただし、あなたの場合、Androidデバイスが2つあるため、リソースを事前設定することはできません。アカウント名やIMEI番号など、Androidデバイスで一意の識別子文字列を使用することをお勧めします。

リソース文字列を使用して、特定のユーザーに送信することができます。

admin@server/12345 

ここで、12345はリソースまたは

admin@server

すべてのログインユーザーに。

アプリケーションでリソース文字列を使用していない場合は、を使用StringUtils.randomString(20)して20文字のランダムな文字列を生成できます。StringUtilsSmackパッケージに含まれています。

于 2010-08-04T02:57:44.877 に答える
5

原則として、ジャバーメッセージはサーバーに接続した最後のデバイスに送信されるため、接続している場合は

youruser@yourserver.org

2つの異なるデバイスから、後で接続したデバイスがメッセージを受信するデバイスになります。

ただし、リソースを指定すると、すべてが簡単になります。たとえば、ラップトップと携帯電話から接続している場合、リソースを使用して完全なjid(jabber id)でログインできます。

youruser@yourserver.org/laptop

youruser@yourserver.org/cellphone

ここで、携帯電話から接続されているクライアントが受信するジャバーメッセージを送信する場合は、メッセージが「youruser@yourserver.org」ではなく「youruser@yourserver.org/cellphone」に送信されるようにしてください。

于 2012-08-22T07:53:45.743 に答える
3

The reason your only getting the item delivered to one device and not both is that Tigase, unlike Google Chat, is following the XEP and delivering the message to the connection with the lowest priority (or to the device that logged in last if the priority is the same.)

You need to be careful when trying to bind your JID to a specific resource and look to make sure the resource you requested was actually assigned. The server may not give it to you because it conflicts with an existing JID's defined resource.

Google Chat servers do something "special" in that they deliver the message to any connected JID regardless of resource or priority setting. There are some changes being suggested to allow that behaviour by design but those have not yet been accepted by the XSF yet.

If you want delivery of messages to all connected devices I would suggest that you look into creating a PubSub node on your Tigase server and set the node to deliver to any online JID - then all of your devices will receive any message that you push to the node if they are online.

于 2010-08-13T16:36:01.610 に答える