getting SocketTimeoutException while using smack 4.1.2 in android to connect to my ejabberd server - xmpp

I am trying to connect to ejabberd server using smack API 4.1.2 (no asmack) on android device. while running smackClient program , I am getting below error
java.net.SocketTimeOutException:Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms,'abc.example.com:5222' failed because java.net.ConnectionException: Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms
Connection to same ejabberd server using same android device is working fine using xmpp clients like xabber. so Issue is surely with client code I have written. Below is the snippet of my code
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(userName, password)
.setServiceName("abc.example.com")
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setSendPresence(true)
.build();
connection = new XMPPTCPConnection(config);
connection.connect();
connection.login(userName, password);
I am missing something in my client code that xabber is having so xabber connection is working from same device using same credential.
Please help

Hard to tell without real IP and names in your example. However, my best guess would be about how the address to your IP server is resolved.
There seems to be discrepancy in your example with server (example.com) and service name in your code (abc.example.com).
My guess it that your client is attempting to connect to another machine that the one the XMPP server is running on.
So, here are the things to check when you have issues with a server not replying:
Check how the address of the domain is resolved. You may need to specify another machine name that the domain. If this is a test domain, there is possibly not a DNS setup, so you may even need to specify server IP (while still configuring the client to use an XMPP domain, that's two different things).
In client, log the IP you are trying to connect to, to make sure this is the one where the server is running.
If server is not on the main domain server, you may even need to do DNS SRV record queries for XMPP C2S service.

For me , it took hours to find the solution.
I forget to turnoff the VPN application(Express VPN) .Network tunneling was the root cause .
And change the Network protocol version properties as below ,
Choose the 1st option (Obtain DNS server address automatically).

My experience: I used following code
DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("desktop-urvfr83");
//DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("192.168.1.3");
InetAddress addr = InetAddress.getByName("192.168.1.3");
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("alir", "111111")
.setHostAddress(addr)
.setResource("phonn")
.setXmppDomain(xmppServiceDomain)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(5222)
.build();
but it could not connect and produced timeout connection exception. When I disabled windows firewall it worked correctly and connected.

Related

Failed to connect to localhost/127.0.0.1:7443

Hi i am using openfire as my im server to my mobile app client, I have added the Httpfileupload plugin to openfire and enabled the http bind settings, when I try to upload a file it shows me this error Failed to connect to localhost/127.0.0.1:7443 ,
and the servers send me this XML message <get url="https://localhost:7443/httpfileupload/45726202-5e69-4b5c-a533-00d82f6d1121/4add76e7f15b6b4f.png"/>
I’ve tried to access this uri but it doesn’t work
please help me with this issues
i am using the latest smack version and the latest openfire version also
You appear to have set up Openfire using the value 'localhost' as its XMPP domain and/or fully qualified domain name for the server that is running Openfire. This is a recipe for disaster. Openfire is broadcasting the address of the content that is managed by its HTTP File Upload plugin, and uses the value that was configured, 'localhost'. Clients, which typically run on different machines, will try to connect to this host. As they're instructed to connect to 'localhost', they'll never be able to reach Openfire.
My advise is to setup Openfire again, and use proper, network-reachable addresses for values of the XMPP domain name and FQDN (these are asked for in the second page of the setup wizard, if memory serves).

unable to connect to openfire server with external ip

I'm trying to connect to openfire server using spark. I have dynamic dns, made port forwarding on port 5222 in d-link router. When i'm logging with host name as private ip for example "192.168.0.101" - connection is established, but when i'm setting my domain (pizokas.hopto.org) as host name i get the following error
Unknown connection error. Please review logs for the following information.
But there are no logs in openfire server, so i assume packets are dropped in router. I have firewall turned off. At this point i can't find information why the connection cannot be established. I'm using my own laptop as server and as a client, os win 10. Maybe somebody had similar issue?
The connection was established when i was trying to connect to server from outside of lan

Java Web application not sending Email on Ubuntu server

My play framework web application sends automatically emails to user using Apache commons email library, everything works fine on my machine, but when I deploy it on an Ubuntu server it is unable to send email.
It throws exceptions like org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.googlemail.com:465 (I also tried different configuration with smtp.google.mail port 465,25 and 587 with or without ssl and tls)
and connection timed out.
I starting to believe that is a problem of some configuration of my ubuntu server.
Any suggestion?
If i type ufw status command I receive status disabled.
Thanks
I am going to close this question, because I found the solution. Basically my Server provider (Scaleway) has a security configuration where SMTP is blocked. I asked them to unlock It.

Connect to C++ REST sdk SERVER on Windows from LAN

I have a server written on C++ REST SDK.
There's http_listener which listens to "http://localhost:34568".
When I try to send a request in browser or from the client to localhost it works fine and I get the responses from my server. But the point is to use the application in network. And here where the problem comes.
When I try to request the server from the other PC using IP(192.168.1.103:34568) I get "HTTP Error 400. The request hostname is invalid."
I'm aware that that could be some firewall issues but it's turned off. Also I tried to set port rules in brandmauer and it didn't help.
And even more! I got XAMPP running Apache server and when I do the same thing but with (192.168.1.103:80) I do get the response from Apache and have an access.
Anybody had something similar or somebody knows what the problem is about?
Listen to local ip address or to your network name (dns):
"http://xxx.xxx.xxx.xxx:34568" or
"http://your_network_name:34568"
So, if you have multiple network adapters, you can choose which one.

What's Difference Between Ubuntu Server (32bit) and Desktop (32bit) In Socket Programming

I am working on a server/client based project. I almost finished my server side code.
I develop the server app in EclipseCDT on Ubuntu Desktop, and everything just works fine.
But when deploy my app to a Ubuntu Server (I tried Server 10.04/10.10), the server app can start normally (waiting for connection), but the same client just cannot connect to the server.
I use Socket for receiving and sending data to/from the client.
Peter
P.S.: if I install sudo apt-get install ubuntu-desktop on my server machine, then everything works fine again.
===========================================================================
New Findings from the source code:
LabelStartBlocking:
int newScoketId = ::accept(socketId, 0, 0); // socketId == 3 ::accept is define in socket.h
// waiting for connection
LabelResume: // if new connection coming
// Do something with newSocketId
The behavior difference between Ubuntu Desktop and Server is:
On Ubuntu Desktop version, when the server starts, it is blocked at LabelStartBlocking with the socket routine ::accept; and then if a new connection arrives, the server will resume at LabelResume and create a new socket connection using the return value newSocketId;
However, on Ubuntu Server version, when the server starts, it is also blocked at LabelStartBlocking with the socket routine ::accept, but if a new connection arrives, the server won't resume at LabelResume, and the new socket connection CANNOT be created.
Can you guys help me out?
Peter
Thanks for your attention.
I finally figured it out.
If there are more than one IP addresses for the same hostname (/etc/hosts), the old code will fail.
Example /etc/hosts file:
127.0.0.1 localhost YourHostName
10.50.10.251 YourHostName
I traced the calling stack, and I found that, the IP address (10.50.10.251) passed to the program is translated into hostname, and then later the hostname is translated back to IP address (for binding), but a DIFFERENT one, that's why my server program cannot accept any client connection.
Hope it helps if any others have the similar issue.
Peter