When I enter my base URL it refuses to connect, which means I probably have the wrong URL. This is what I currently have:
public static final String BASE_URL = "http://127.0.0.1:5984/_utils/";
What would the base URL be? Any examples would be helpful.
The localhost refers to the device on which the code is running, in this case the emulator.
There is however a far better solution. You can access your host machine with the IP address "10.0.2.2".
This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via http://10.0.2.2:5984/_utils/
please try with below code
public static final String BASE_URL = "http://10.0.2.2:5984/_utils/";
Related
I programmatically (Azure, Java SDK) create Virtual Machine Scale Set ((Linux OS - Ubuntu) with ".withVirtualMachinePublicIp()" option during the creation. It works OK, I can see the instances and their public IP Addresses in the Azure Portal. I can ssh into the instances, etc... However I cannot get the public IP Addresses via Azure Java API, it always returns null. I tried a lot , the below code is just one of the attempts.
//vmss is a good working recently created instance off
//com.azure.resourcemanager.compute.models.VirtualMachineScaleSet class
for (VirtualMachineScaleSetNetworkInterface nis : vmss.listNetworkInterfaces())
{
String privip=nis.primaryPrivateIP();//works OK
Map<String, VirtualMachineScaleSetNicIpConfiguration> mp=nis.ipConfigurations();
for (Object key: mp.keySet())
{
VirtualMachineScaleSetNicIpConfiguration vip=mp.get(key);
String priva=vip.privateIpAddress();//works OK
String pipa=vip.innerModel().publicIpAddress().ipAddress();//always returns null
String pss=vip.innerModel().privateIpAddress();
System.out.println("PublicIP="+pipa+",PrivateIP="+priva+"="+pss);//Public IP is always null
}
}
I tried the above code but always receive null value as Public IP Address
I was helped on Git Hub. There is workaround:
https://github.com/Azure/azure-sdk-for-java/issues/33299#issuecomment-1415416429
I recently started a chat app that works with Firebase Auth & Database,
now for security reasons I want to save their IP's on the Database...not their local one (192.168...), I want to save their external (91.22....). I'll add this aswell to the GDPR but I don't know the code for that.
Is there a short Java Source Code?
like "android.os. ..." Code?
I also tried some else codes but it did not worked aswell.
I appreciate ya' answers :)
Is there a short Java Source Code?
No.
like "android.os. ..." Code?
No. The device does not necessarily know its external IP address, just like a desktop or notebook does not necessarily know its external IP address.
Make a request of your Web service, and have your Web service note what IP address the request comes from.
If you are using a socket you can do socket.getInetAddress().getHostAddress()
If you want the device you get it's own public IP address, you can use this method:
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
String ip = in.readLine(); //IP as a string
System.out.println(ip);
I'm trying to make a connection to xmpp server and this returning me this error.
W/AbstractXMPPConnection: Connection closed with error
org.jivesoftware.smack.XMPPException$StreamErrorException: host-unknown You can read more about the meaning of this stream error
at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1003)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:944)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:959)
at java.lang.Thread.run(Thread.java:818)
I tried to use this example in github and put this data.
private static final String DOMAIN = "10.20.0.125";
private static final String HOST = "10.20.0.125";
private static final int PORT = 5222;
private String userName ="admin2#localhost";
private String passWord = "asdfasdf";
The server is ok, we conducted another test pc to make a communication on android but this error persists.
I see mainly 2 errors:
in the demo configuration you have this lines of code:
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(userName, passWord);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setResource("Android");
configBuilder.setServiceName(DOMAIN);
configBuilder.setHost(HOST);
configBuilder.setPort(PORT);
First problem (main one):
DOMAIN variable SHOULD (but MUST) BE the server name you can read in server configuration, not just the IP; some functionality will broke outside the localhost.
Second problem:
while I suggest to split login from configuration (so just configure the connection and THEN login) what I don't get it's the username: localhost will be not resolved outside the server machine, so again has to be replaced with DOMAIN name (even if, in theory, the connection will give the user his domain, doesn't need to be so explicit).
so:
connection.connect();
login();
will be replaced with
connection.connect();
login(userName ,passWord,"Android" );
and you'll need to remove this 2 lines:
configBuilder.setResource("Android");
configBuilder.setUsernameAndPassword(userName, passWord);
about DOMAIN name: you'll find it in Server configuration, in Openfire it's the "Server Name" you can read in web interface in Server Information page.
I managed to find the solution.
I was using .jar files instead of the compile gradle dependencies:
compile 'org.igniterealtime.smack:smack-android:4.1.4'
compile 'org.igniterealtime.smack:smack-tcp:4.1.4'
compile 'org.igniterealtime.smack:smack-im:4.1.4'
compile 'org.igniterealtime.smack:smack-extensions:4.1.4'
Thus the error has been resolved. Thank you for your help.
I have a server-side application written in Java.
We use Jetty to provide our servlets.
Final users use the browser to 'use' our app.
From a server-side point of view when I get an HttpServletRequest is it possible to know if it from a browser which is running on the same machine that the server has been installed on?
(that being the case I am obviously testing and I would like to do something about it)
You can use ServletRequest.getRemoteHost() which returns the fully qualified name of the client that sent the request and compare it to local host name InetAddress.getLocalHost().getCanonicalHostName()
I guess you can check whether the ip address of the request is the same as server's or if it's coming from localhost?
I guess this can help:
String getRemoteIP(HttpServletRequest request) {
String xff = request.getHeader("X-Forwarded-For");
if (xff != null) {
return xff.split("[\\s,]+")[0];
}
return request.getRemoteAddr();
}
Compare this address to server's.
I took this code from here
I'm programming a simple web browser depending on NanoHTTPD project and it's required to get number of visitors using the IP address.
Are there any ways to get the client IP using NanoHTTPD?
In NanoHTTPD.java, find the private class HTTPSession object.
Inside this is public void run(). Find the following line and add the second line after it.
decodeHeader(hin, pre, parms, header);
header.put("IPAddress", mySocket.getInetAddress().getHostAddress());
Now inside your serve function, you can just reference the IPAddress header to get the client's ip address.
I know the answer is probably too late to help you, but hopefully it'll help others searching for the same thing.
I found in the latest master branch, you can get the client ip address by header "http-client-ip" in the IHTTPSession session object.