XMPP 聊天在 Android 和 iOS 设备之间不起作用?

发布于 2024-11-02 17:31:19 字数 1930 浏览 8 评论 0原文

我正在 Android 和 iOS 上开发 XMPP 聊天应用程序。

iPhone 模拟器和 iOS 设备之间的聊天工作正常。 它还可以在 Android 模拟器和 Android 设备之间运行。 但是,它在 Android 设备和 iOS 设备之间不起作用。

任何人都可以向我建议我可能做错了什么吗?

提前致谢...

更新:

消息是从 Android 设备发送到 iOS 设备,但不是从 iOS 发送到 Android。

我在 Android 上使用了这个:

ConnectionConfiguration connConfig = new ConnectionConfiguration(testHost,portNumber);
connection = new XMPPConnection(connConfig);
connConfig.setSASLAuthenticationEnabled(true); 

我在 iOS 上使用了这个:

XMPPJID *jid=[XMPPJID jidWithString:loginDetails.username];

password=loginDetails.password; 

[[self xmppStream] setMyJID:jid];
NSError *error;
if (![[self xmppStream] connect:&error])
{
    NSLog(@"Error connecting: %@", error);
    return NO;
}
return YES;

if (allowSelfSignedCertificates)
{
    [settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
}

if (allowSSLHostNameMismatch)
{
    [settings setObject:[NSNull null] forKey:(NSString *)kCFStreamSSLPeerName];
}

else
{
    // Google does things incorrectly (does not conform to RFC).
    // Because so many people ask questions about this (assume xmpp framework is broken),
    // I've explicitly added code that shows how other xmpp clients "do the right thing"
    // when connecting to a google server (gmail, or google apps for domains).

    NSString *expectedCertName = nil;

    NSString *serverHostName = [sender hostName];
    NSString *virtualHostName = [[sender myJID] domain];

    if ([serverHostName isEqualToString:@"talk.google.com"])
    {
        if ([virtualHostName isEqualToString:@"gmail.com"])
            expectedCertName = virtualHostName;
        else 
            expectedCertName = serverHostName;
    }
    else
    {
        expectedCertName = serverHostName;
    }

    [settings setObject:expectedCertName forKey:(NSString *)kCFStreamSSLPeerName];
}

I am developing an XMPP chat application on both Android and iOS.

Chatting is working fine between iPhone simulator and iOS device.
It's also working between Android emulator and Android device.
However, it is not working between android device and iOS device.

Can any one please suggest to me what I could be doing wrong?

Thanks in advance..

Update:

Messages are coming from Android device to iOS device, but not from iOS to android.

I used this for Android:

ConnectionConfiguration connConfig = new ConnectionConfiguration(testHost,portNumber);
connection = new XMPPConnection(connConfig);
connConfig.setSASLAuthenticationEnabled(true); 

I used this for iOS:

XMPPJID *jid=[XMPPJID jidWithString:loginDetails.username];

password=loginDetails.password; 

[[self xmppStream] setMyJID:jid];
NSError *error;
if (![[self xmppStream] connect:&error])
{
    NSLog(@"Error connecting: %@", error);
    return NO;
}
return YES;

if (allowSelfSignedCertificates)
{
    [settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
}

if (allowSSLHostNameMismatch)
{
    [settings setObject:[NSNull null] forKey:(NSString *)kCFStreamSSLPeerName];
}

else
{
    // Google does things incorrectly (does not conform to RFC).
    // Because so many people ask questions about this (assume xmpp framework is broken),
    // I've explicitly added code that shows how other xmpp clients "do the right thing"
    // when connecting to a google server (gmail, or google apps for domains).

    NSString *expectedCertName = nil;

    NSString *serverHostName = [sender hostName];
    NSString *virtualHostName = [[sender myJID] domain];

    if ([serverHostName isEqualToString:@"talk.google.com"])
    {
        if ([virtualHostName isEqualToString:@"gmail.com"])
            expectedCertName = virtualHostName;
        else 
            expectedCertName = serverHostName;
    }
    else
    {
        expectedCertName = serverHostName;
    }

    [settings setObject:expectedCertName forKey:(NSString *)kCFStreamSSLPeerName];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文