无法使用 react-native-xmpp 连接 openfire [英] Unable to connect with openfire using react-native-xmpp

查看:121
本文介绍了无法使用 react-native-xmpp 连接 openfire的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 react-native 聊天应用程序,我使用 USB 调试在我的 android 手机上运行它,我使用 OPENFIRE 作为聊天服务器.为了与 Openfire 连接,我使用了库react-native-xmpp".下面是使用 react-native-xmpp 连接 OPENFIRE 的代码 --

I have a react-native Chat application which I am running on my android phone using USB debugging and I am using OPENFIRE as a chat server. For connecting with Openfire I am using library 'react-native-xmpp'. Below is the code for connection with OPENFIRE using react-native-xmpp --

import XMPP from 'react-native-xmpp';
var JID = 'admin@192.168.4.246';

XMPP.on('error', (message) => console.log('ERROR:' + message));
XMPP.on('loginError', (message) => console.log('LOGIN ERROR:' + message));
XMPP.on('login', (message) => console.log('LOGGED!'));
XMPP.on('connect', (message) => console.log('CONNECTED!'));

XMPP.connect('ramvallabh@192.168.4.246', 'root','RNXMPP.PLAIN','192.168.4.246',5222);
XMPP.message('Hello world!' , JID);

XMPP.disconnect();

我这里使用的 IP 是我的本地 IP 地址.我正在尝试以 PLAIN 连接的形式连接到端口 5222.但是我收到一个错误说

The IP I used here is my local IP address. I am trying to connect to port 5222 as a PLAIN connection. But I am getting an error saying

客户端需要 SSL/TLS 但不支持或不再支持服务器.

SSL/TLS required by the client but not or no longer supported by server.

我检查了端口 5222 上的 OPENFIRE 配置.我禁用了加密并启用了加密,但在任何一种情况下都没有任何区别.我也尝试连接到端口 5223 然后错误说

I checked the OPENFIRE configuration at port 5222. I disabled the encryption and enabled the encryption but not getting any difference in either case. I also tried to connect to port 5223 then the error says

javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:信任锚未找到认证路径.

javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

我没有上传太多代码,因为我认为错误在于库或一些我不理解的网络概念.有人知道这里可能出了什么问题或有其他更好的方法吗?

I not uploaded much of code because I think the error either lies in the library or some networking concept that I don't understand. Does anybody have any idea what may be going wrong here or any other better way to do it?

推荐答案

您遇到此错误是因为在 raect-native-xmpp 的 java 代码中,默认启用了安全模式.如果您想使用纯文本身份验证,则必须将其关闭.

You are facing this error because in the java code of raect-native-xmpp, security mode is enabled by default. If you want to use PLAIN text authentication than you must turn this off.

示例:假设您的 react-native 应用名称是 TestApp,然后转到以下目录:TestApp/node_modules/react-native-xmpp/android/src/main/java/rnxmpp/service并转到第 76 行并替换为以下行:

Example: Suppose you react-native app name is TestApp then go to the following directory: TestApp/node_modules/react-native-xmpp/android/src/main/java/rnxmpp/service and go to Line 76 and replace with the below line:

之前:

.setSecurityMode(ConnectionConfiguration.SecurityMode.required);

.setSecurityMode(ConnectionConfiguration.SecurityMode.required);

之后:

.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

这篇关于无法使用 react-native-xmpp 连接 openfire的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆