Reputation: 10502
I am looking for a simple exmple to connect ejabbered
using smack
java client. Here is something i tried
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
builder.setUsernameAndPassword("admin1@ejab", "123456");
builder.setServiceName("ejab");
builder.setHost("localhost");
builder.setPort(5280);
XMPPTCPConnectionConfiguration build = builder.build();
AbstractXMPPConnection conn1 = new XMPPTCPConnection(build);
conn1.connect();
I am getting
org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'
i am able to browse http://localhost:5280/admin
. What is servicename
& host
. Can anyone give a simple example ?
Upvotes: 0
Views: 817
Reputation: 141
According to smack API, setServiceName parameter should be the domain of the XMPP service, so, in your case, it should be "ejab" (I suppose account "admin1@ejab" is correctly set in ejabberd). You can check with the section Hostname at ejabberd.cfg file.
e.g. from default ejabberd.cfg file
%% Hostname
{hosts, ["localhost"]}.
==> localhost is set as the service name
The setHost function parameter should be the server IP address or DNS resolvable server name. From your description that you access the ejabberd admin page using localhost, use the computer IP address that installed with ejabberd will be simpler.
Also, setPort should be the port that ejabberd listening at and its default is 5222 instead of 5280 (5280 is for administration through web). You can check with the listening ports from the ejabberd.cfg file to confirm.
e.g. from default ejabberd.cfg file
{listen,
[
{5222, ejabberd_c2s, [ .........
Below are the steps for adding a self signed certificate such that smack can work with. (Note : I use ubuntu server for following commands with openssl installed.)
create a certificate
openssl req -new -x509 -newkey rsa:1024 -days 3650 -keyout privkey.pem -out server.pem
openssl rsa -in privkey.pem -out privkey.pem
cat privkey.pem >> server.pem
openssl rsa -in server.pem -out newcert.pem
openssl x509 -in server.pem >>newcert.pem
sudo cp newcert.pem /etc/ejabberd/
modify ejabberd.cfg to use the certificate
{5222, ejabberd_c2s, [
{access, c2s},
{shaper, c2s_shaper},
{max_stanza_size, 65536},
starttls, {certfile, "/etc/ejabberd/newcert.pem"}
]},
{s2s_use_starttls, true}.
{s2s_certfile, "/etc/ejabberd/newcert.pem"}.
restart the service
sudo service ejabberd restart
Upvotes: 1