Unable to connect with openfire using react-native-xmpp

怎甘沉沦 提交于 2021-01-27 04:41:09

问题


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();

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 required by the client but not or no longer supported by server.

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: 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?


回答1:


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.

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:

Before:

.setSecurityMode(ConnectionConfiguration.SecurityMode.required);

After:

.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);



来源:https://stackoverflow.com/questions/49429661/unable-to-connect-with-openfire-using-react-native-xmpp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!