Strophe.js does not connect to openfire - android

I set up an openfire server on a server within our network and gave it a domain name. I want to connect to it via my phone in a phonegap app and therefore implemented a strophe.js client within my app.
It works fine on my Nexus 5 (Android 4.4.3), but as soon as I want to run it on my Samsung Galaxy S2 (Android 4.1.2) or the Samsung Galaxy Tab (GT-P7501 - Android 4.0.4) I don't get any response from the server. Here is the code snippet of my connect:
var BOSH_SERVICE = 'http://SERVERNAME:7070/http-bind/';
var connection = null;
$(document).ready(function () {
connection = new Strophe.Connection(BOSH_SERVICE);
connection.rawOutput = log;
connection.rawInput = log;
connection.connect('id#servername/resource', 'test', onConnect);
});
function log(msg) {
console.log(msg);
}
function rawInput(data) {
log('RECV: ' + data);
}
function rawOutput(data) {
log('SENT: ' + data);
}
the console log will be:
SENT: <body rid='367573377' xmlns='http://jabber.org/protocol/httpbind' to='servername' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
This will be repeated a few times but I don't get any incoming messages. The servers version number is openfire 3.9.3. As all this code works on my nexus 5 I assume that the code is correct. I Also doubt that my server is configured wrong, nevertheless I included a screenshot of the config settings of the openfire server in the end.
The openfire xmpp server is running on a windows server and I access it via wifi/dyndns.
Do you have any ideas why this does not work on the samsung galaxy? Every help will be appreciated. Thanks in advance !

I could "solve" this by myself. It is really not a big deal, but it took me a really long time (3 days) to realize this, so in case anyone will ever come accross the same phenomena this info might help:
In my case all the configurations of the server and the strophe client above are correct. Indeed the only reason the connect did not work properly on all devices seemed to be that these devices could not even ping the server, even though they are in the same network. In my case I gave the server a static domain name, which was the key issue. Somehow the Google Nexus 5 is able to resolve this name to an ip adress via the dns-server, but both the elder samsung galaxy s2 and the samsung galaxy tab aren't.
Solution: I replaced the static domain name with the corresponding ip-adress in my strophe.js connection.

Related

Flutter "Connection Refused" (errno=111) when trying to send an http get request to from physical device to pc

I built a flutter app which communicates with a web server that I wrote with flask. Everything works as intended without any errors if I use a virtual device. As soon as I try it in release mode on a physical device I get problems when it comes to the communication with the server
The only thing that I changed when using a physical device is the ip. I use 10.0.2.2 on the virtual device and my computers ip4 adress - that I get with ipconfig in windows 10 - on the physical device
Both devices are in the same network connected to the same router
Internet Permission is enabled in the AndroidManifest for all modes (Debug, Main, Profile)
I even disabled the firewall
The line that causes the issue is
await http.get(url).timeout(Duration(seconds: 15), onTimeout: () {
// Handle timeout
// This entire thing is in a try-catch block in an async function
});
In debug mode on the physical device when the HTTP get request is sent VSCode immediately says
Exception has occurred.
SocketException (SocketException: OS Error: Connection refused, errno = 111, address = 192.168.178.20, port = 43378)
First Question: Why Port 43378? Is that the port the HTTP request is sent to? Because when I run the flask app it says:
Running on http://127.0.0.1:5000/
Could that be the issue? I would have expected the exception to say the port is 5000 as declared in the URL. Or do I have to change something with how I set up the flask app? Currently it is the development server because I am still testing before I pay money and deploy
However I hope I didnt forget any important information. Any advice on what could be wrong or how to debug here is highly aprecciated
Pass an Uri object to http.get func. Uri classes let you specify the port as Documentation https://api.dart.dev/stable/2.12.0/dart-core/Uri-class.html

socket io server is not responding when android emulator or Samsung S9+ are trying to connect but working fine with Kindle device

We are trying to create an android application for video chat using socket.io. We are using node js for the server. The server is running on a laptop. I tried to connect to the server using an Android emulator on the same laptop. But the server is not responding. I thought we shouldn't try to connect the emulator running on the same laptop where the server is running. I tried with Samsung S9+ device but the same result, the server is not responding. But interestingly when I tried to connect to the server from the Kindle device, the server is responding and printing the log. I used the same code for Emulator, S9+, and Kindle devices. Only when kindle device is trying to connect, the server is responding. Below is the code.
Android code:
String SIGNALING_URI = "http://192.168.1.101:7000"; // Laptop IP where the server is running and port 7000 where the server is listening
try {
socket = IO.socket(SIGNALING_URI);
socket.on(CREATEOFFER, new Emitter.Listener() {
#Override
public void call(Object... args) {
createOffer = true;
peerConnection.createOffer(sdpObserver, new MediaConstraints());
}
});
socket.connect();
} catch (URISyntaxException e) {
e.printStackTrace();
}
Node.js (server) code:
var socketIO = require('socket.io');
var server = require('http').createServer().listen(7000, '0.0.0.0');
var io = socketIO.listen(server);
io.sockets.on('connection', function (client) {
console.log('new connection: ' + client.id);
client.on('offer', function (details) {
client.broadcast.emit('offer', details);
console.log('offer: ' + JSON.stringify(details));
});
client.on('answer', function (details) {
client.broadcast.emit('answer', details);
console.log('answer: ' + JSON.stringify(details));
});
client.on('candidate', function (details) {
client.broadcast.emit('candidate', details);
console.log('candidate: ' + JSON.stringify(details));
});
client.broadcast.emit('createoffer', {});
});
Server code should print "new connection: " log when a client is trying to connect. But it is not printing that log when Android emulator or S9+ device are trying to connect but the log is getting printed when Kindle is trying to connect. I tried to do this using web sockets instead of using socket io. The server is responding for kindle device only even using web sockets also. Can anyone please let me know if there is anything wrong in the code or do I need to change any settings on S9+ device and emulator to make it work?
Update 1:
It seems I am using socket.io-client:0.8.2 version. But on the server node js, it seems I am using socket.io 2.3.0. Does it create any problems. Where I can find compatible versions of socket io for java and node.js. Just wanted to make sure that compatibility is not causing this issue.
Update 2:
I am able to see "new connection: " on the console multiple times with different client IDs. But these logs are not generated when I was trying to connect on Emulator or S9+ device. To make sure, I tried to print socket ID on client side after IO.socket(SIGNALING_URI) by using socket.id() which is printing null on the client side.

Cordova Backbone App - Ajax requests failing on specifically LG G4s + Samsung S7 w/ Wifi on

Issue
I have an App built in backbone.js and Cordova. It is having issues making an Ajax request in a very niche situation - specifically this issue happens only on an LG G4 (and Samsung S7) with the Wifi On. It likely has issues on others but I've only tested 4 phone models so far. I am using jQuery to make an Ajax call.
What I mean by issues making an Ajax request is that the request actually fails. In my developer tools on the Network tab, the status shows (failed). If i console log the XHR.status it shows a 0.
If i console log the thrown error I get the following...
DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://mywebsite.com/Unicorn/API/FooBar.svc/JSON/DoThisPlease?var1=whatisone&var2=morestuff&clientInfo=Android%20undefined%206.0'
Code
The code for my request is as follows...
function doSomeAjaxCall(successCallback, failureCallback) {
var deviceInfo = getDeviceInfo();
var request_url = baseUrl + "DoThisPlease?var1=" + encodeURIComponent(varA) + "&var2=" + encodeURIComponent(varB) + "&deviceInfo=" + encodeURIComponent(deviceInfo);
$.ajax({
url:request_url,
async:false,
success:function (json) {
if (json === "") {
failureCallback("Invalid email and/or password");
} else {
successCallback(json);
}
},
error:function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status === 404)
failureCallback('The API was not found at this URL');
else if (jqXHR.status === 0)
failureCallback('Cannot connect to PD, make sure your device is online.');
else
failureCallback('Server Responded with: ' + jqXHR.statusText);
}
});
}
Things I've Tried
It should be noted that if I take the request url and paste it into a web browser it will also not work on Wifi.
This all being said, the minute I disable Wifi and data takes over everything works. I have tried the app in the following data settings:
Wifi On Data On Result Fails
Wifi On Data Off Result Fails
Wifi Off Data On Result Works
Phones I've Tried
Samsung S6 Android 6.0.1 Works on all Data Configurations
LG G3 Android 6.0 Works on all Data Configurations
Lg G4 Android 6.0 FAILS (with Wifi On see above configurations)
Samsung S7 Android 6.0.1 FAILS (with Wifi On see above configurations)
Version of Chrome on all devices is 53.0.2785.124
I can't quite wrap my finger around why this issue is happening. Any feedback on this issue or debugging Cordova apps in general would be nice.
I am currently debugging using chrome's inspector over ADB with the phone plugged in to USB.
EDIT 10/20
As per #Gandhi's suggestion I tried hitting other APIs. I was able to hit an API on a different machine - I used the Federal Reserve Economic Data API. I tried hitting a different API on the SAME machine and it had the same errors as attempting to make an AJAX request to the original API did. I also did some testing on a Samsung Galaxy S7 and it's results are the same as the LG G4.
Thought 1: I have an IIS server and I am starting to wonder if there is some sort of configuration issue on new Android phones (models, not Android software version) or the IIS server that is causing this issue.
Thought 2: I am going to do some testing today and try getting out of the office with the phones and trying a Wifi connection on a different network. I wonder if the way network requests are made on certain phone models might interact differently with our network. I'm not much of an expert on the Android OS itself but I think phone model shouldn't matter as the OS (version of Android) would handle the requests (just using the phone model's hardware) and conform to some standard for the requests. Regardless I'm going to try this today and update with results.

Receiving UDP on different Android phones gives different results

I am willing to create a server and client program on my android mobile devices.
The devices communicate with each other on the same wifi network, therefore, some simple scanning mechanism must be implemented - The client phones search for a server phone through some kind of broadcast.
What I did:
My protocol - the client phone broadcasts a message port p on the wifi, the server listens on port p. when the server gets the broadcast message it sends a message back, therefore discovering itself to the client.
My code -
I have opened a broadcast socket on my app, it sends a broadcast message.
Meanwhile there is a python script on my PC that listens and replies - I use python so that my testing will be easier - Wireshark on the PC and I can see everything.
What happens:
When I use one of my Galaxy S phones - it works and I get a response.
When I use the other Galaxy S phone - it doesn't work.
Now this is what I know:
The phone that works actually has Nexus ROM on it Ver. 4.1.1
The phone that doesn't work has 2.3.3 regular galaxy ROM
The python code says it receives both of the broadcasts sent from both phones, and replies to both of them without raising any exception.
So far I was thought the problem may be
1. the older version'd phone.
2. the windows firewall
3. the router firewall
So I have opened Wireshark, and Indeed I saw that both phones are sending their broadcasts - it was logged on Wireshark.
But the python script only responded to the first one.
So this is why 1 & 3 are irrelevant - if the router firewall was blocking my UDP I would have still seen the python server response, same with the older versioned phone.
To get rid of 2 i just disabled the windows firewall - still same problem.
Does anyone has a clue to why this effect might happen?
Thanks!
Edit
My python code:
def scan(data, addr, sock):
print "received scan message:", data, addr
name = u"name".encode("utf-16-le")
data = "DISC" + short2bytes(len(name)) + name
print "sending back %s to %s" % (data, addr)
sock.sendto(data, addr)
if __name__ == "__main__":
sock = socket(AF_INET, SOCK_DGRAM)
sock.bind(('', UDP_PORT))
while 1:
data, addr = sock.recvfrom(1500)
print "received packet " + data
if data.startswith("SCAN"):
scan(data, addr, sock)
edit 2:
Okay! Seems like my code and protocol DID work.
As it turns out the 2.3.3 phone had some severe ARP problems.
After some resets it works flawlessly!

Android bluetooth pbap get request failure

everyone.
I try to implement a pbap client on Android platform.
My client can get phonebook from most of android phones.
But when I connect to HTC G11, it does not work normally.
my main code is as follows:
mSocket = mDevice.createInsecureRfcommSocketToServiceRecord(ParcelUuid.fromString(PBAP_UUID).getUuid()); //it's OK here
mSocket.connect(); //it's OK here
mClientSession = new ClientSession(transport); //it's OK here
HeaderSet request_conn = new HeaderSet();
request_conn.setHeader(HeaderSet.TARGET, PBAP_TARGET);
HeaderSet return_header = mClientSession.connect(request_conn); //it's OK here
When mClientSession.connect(request_conn) called, remote device give a response code OBEX_HTTP_OK.
It means remote device accepted my pbap connection request.
But problem come out after that.
HeaderSet request_get = new HeaderSet();
request_get.setHeader(HeaderSet.NAME, name);
request_get.setHeader(HeaderSet.TYPE, type);
mGetOperation = (ClientOperation)mClientSession.get(request_get);
mInputStream = mGetOperation.openInputStream(); // problem come out here
I send a get request to remote device but remote give a response code 211 which means
OBEX_SERVICE_UNAVAILABLE. So I cannot get phonebook from htc G11.
I try Nokia N9, it is the same with HTC G11. Nokia N9 give a response code 211 too.
But Nokia N9 and HTC G11 can transfer phonebook each other,
and both of them can get phonebook from android phones.
Android implement pbap session layer APIs in framework/base/obex
I guess HTC G11 does not use the standard android session layer APIs.
But what does it use? what about Nokia N9?
Can anyone give me an answer or some right codes? Please help me.
I suffered from this problem a lot.
Thanks!
My email: yulf88#gmail.com

Categories

Resources