GET request to server `http://desktopName` over LAN through mobile - android

My app is trying to lock desktop's mouse and keyboard using a mobile app, which is already working.
I am already using the desktop IP but now trying to use http://desktopName as GET URL for my android app but it is not working.
I am using Framework7 app.request.get for my client.
CLIENT
// var server = "http://192.168.31.147:8089" // working in mobile browser and app
var server = "http://desktop-s5n5hiq:8089" // not working in mobile browser and app
$$("#server").html(server)
app.request.get(server+"/connect").then((res) => {
var data = res.data
I am using node http module for my server.
SERVER
This server is already working without issue.
var http = require('http');
var host = "desktop-s5n5hiq"
var port = 8089
http.createServer(function (req, res) {
...
}).listen(port,host,()=>{
console.log("running server: http://"+host+":"+port)
});
My server IP is constantly changing because my router has no IP lock or IP reservation option, that's why I want to use the desktop name instead (http://desktopName), however, I am not getting any response from my server when I use the desktopName
These are already working:
Connect to http://desktopName using desktop and laptop browser
Connect to IPs http://192.168.1.* using desktop, laptop and mobile browser
Not working:
Connect to http://desktopName using mobile browser. (No "Desktop is connected" log)
Any comment is much appreciated.
Edited:
I forgot to mention that we have 2 routers one is an extender. The main one has this 192.168.1.1 DNS server, however, the other has 192.168.31.1. During desktop boot, it sometimes connects to the main router and sometimes to the extender.
I have tried this solution https://kb.netgear.com/27476/How-do-I-set-a-static-IP-address-in-Windows (added 192.168.1.5) but I think it will cause an issue if the PC connected to the extender.

Related

how to get android emulator to connect to a specific port on our server

I am using Xamarin Forms to build an Android app. The data that the app will consume is stored on our server in a SQL database on our local network. I am using a C# Web API service (served by IIS) to connect the app to the server. All traffic will be inside our local network.
Currently the Web API is being served by IP address on port 90 - this was the only way I could get the emulator to be able to connect to the server, as no luck accessing it by name. I can fire up a browser on my development machine and load up http://10.1.1.15:90/api/Controller and I get back the data I was expecting.
I have also done a networkaccess check for access to 10.1.1.15 on port 90 using Powershell from my machine, which comes back Fine.
I use James Montemagno's Connectivity package to check for network access in the app - this returns true if I check for the IP address. It returns true if I check for the IP address on port 80. However it returns false if I check for the IP address on port 90. How can I get this to access the server on port 90? (BTW it will also need to access other services on port 91 and 92).
The android device was set up by default with a proxy. I toild it not to use the proxy and then it worked

Can't connect on local server

I am developing an app in ionic and I can't connect to the socket server when running on a device.
I have managed to connect my app (port:8100) to a node server(port:9000) locally when developing (via ionic serve), I don have a cors issue, everything runs fine.
Client looks something like this :
socket = new io.connect('http://192.168.1.106:9000');
socket.on('reconnect_attempt',function() {
alert('crap');
});
P.S: the above code is from my own memory, but I know I have provided the ip and port
If the server is working or not I still get the alert...
I have also checked the manifest of the app and it has the appropriate permissions:
android.permission.INTERNET
I also added a js error handler to check if there is a js error:
window.onerror = function (errorMsg, url, lineNumber) {
alert(errorMsg);
}
var MyApp = angular.module('scotch-todo', ['ionic']);
...
I had a small error and fixed it (so the handler works) but now nothing is catched...
If I understand correctly, you can connect when developing on your PC, but now when testing on your physical device.
Since Cordova v4, they changed the default behavior so it won't connect to any address outside its own WebView pages. There exists a cordova whitelist plugin that lets you connect to a list of address in the whitelist
http://docs.ionic.io/docs/cordova-whitelist

Unable to Access webservice from a mobile web browser

I am new to webservices and I am creating an android application that will send and recieve data from a webservice. I have created a REST webservice in Eclipse using Java. I have used Tomcat server.
I am running the webservice on my localhost (Dell laptop with Windows 10 OS).
When i am running the webservice and providing data on my localhost, the service is Returning JSON data successfully but when I am trying to access the same service from my smartphone's chrome browser, its showing ERR_CONNECTION_TIMED_OUT.
Note: Both devices are connect to same network. (I am using MTS blaze)
Things I have tried till now,
Enabled ICMP in firewall settings
Turned off firewall
Uninstalled Mcafee
But no success. Let me know if more information is required to solve this issue.
Edit1:
Url on localhost: localhost:8080/Credentials/register/doregister?user=abc&pass=efg
Url when accessing from smartphone:
192.168.1.100/Credentials/register/doregister?user=abc&pass=efg

Why can't I connect my Android device to localhost using the Intel XDK app?

I'm a novice in app development. I'm using the Intel XDK to make an Android app.
The app works by connecting to a database in a backend done with Symfony, and is behaving fine in the emulator. I want to test now from a real device, using my PC as localhost, through WiFi. I read that you have to retrieve the localhost IP address with ipconfig, and then use that IP for the connection. However, when I test the app it doesn't connect. The strange thing is that if I use the mobile browser with the same URL, the connection works: I can see the XML files that I use to fetch the database information.
The code for the connection in the app:
xmlhttp=new XMLHttpRequest();
xmlhttp.onerror=transferFailed;
xmlhttp.open("GET","http://192.xxx.x.x/symfony/web/app_dev.php/api/v1/reportes/reportes.xml",false);
The onerror function:
function transferFailed(e) {
alert("Error al conectar:"+e.target.status);
}
As I said, the connection doesn't work and I get the alert message: "Error al conectar: 0"
If I put the address http://192.xxx.x.x/symfony/web/app_dev.php/api/v1/reportes/reportes.xml in the mobile browser I get the correct XML file.
Edit: Well it seems the problem was the sycnhronus request. Later i had to parse the response xml. I dont' know why in the emulator and in an app that i made in phonegap some time ago it worked without parse. The code:
function mapIni() {
xmlhttp=new XMLHttpRequest();
xmlhttp.onerror=transferFailed;
xmlhttp.open("GET","http://localhost/symfony/web//app_dev.php/api/v1/reportes/reporte.xml",true);
xmlhttp.onload= function (event) {
alert("onload:"+xmlhttp.response);
};
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
xmlDoc=xmlhttp.responseXML;
xmlDoc=xmlhttp.responseXML;
xmlDoc = new DOMParser().parseFromString(xmlhttp.responseText,'text/xml');
x=xmlDoc.getElementsByTagName("entry");
alert("x[0]:"+x[0].getElementsByTagName("tipo")[0].childNodes[0].nodeValue);
}
}
xmlhttp.send();
}
It may be failing because of Cross-Origin request, add this script tag: <script src="xhr.js></script>" and try on device. You don't need the actual xhr.js file, just add the script tag in index.html, the Intel XDK build will include it to workaround the Cross-Origin policy.
I can see two possible issues. Synchronous use of XHR is often a problem if you are expecting the rest of your javascript runtime to be responsive while the network request is executing.
I would first try asynchronous requests (which really should be preferred anyway):
xmlhttp.open("GET","...",true);
You may have to send the request after opening it (this is certainly true for non-GET requests, but maybe GETs work without sending, but I'm suspicious)
xmlhttp=new XMLHttpRequest();
xmlhttp.onerror=transferFailed;
xmlhttp.open("GET","...",true);
xmlhttp.send();
Finally, presumably you have some handler attached to the onload event for when this does work for you :)
xmlhttp.addEventListener('onload', function (event) {
console.log(xmlhttp.response);
});
Additionally, while the simulator is on the same machine and recognizes localhost, your actual Android device cannot interpret where is localhost. For the device build, change localhost to the server name, under windows this the computer name that was assigned when you first installed windows, and test through a browser ensuring that you can access the files via the computer name. Once verified, than change localhost to your computer name. You also have to ensure CORS is permitted and enabled.

How do you access a local port 8080 url from an android http get

I have a restful web service located on a local tomcat instance.
I'm trying to access the url via a get in my application but am getting the error: host is unresolved
I try to access this url from my android emulator browser to confirm the connection there and am unable to get to it their either. An alert comes up on the screen that says: "an sd card is required to download 125562.bin"
I am not using localhost in my url but something that looks like:
http://192.168.1.2:8080/service/0/12345
It returns straight json
Does anyone know why I can't access this in the android emulator? I can successfully hit this same address from my computer browser as well as iPhone and it brings back json.
Does android handle other ports differently than standard port 80? Is the problem this url doesn't have an extension?
The Android-Emulator has a virtual router, which cut's the Emulators network from the host-computers network.
However, this router is part of the network, too and enables you to access servers running on the local machine by using the IP 10.0.2.2.
So you would use:
http://10.0.2.2:8080/service/0/12345
You need to use 10.0.2.2 to emulate your local machine's 'localhost'.
See Emulator Networking

Categories

Resources