Genymotion communicate with socket in different local subnet - java

I have a virtual machine hosting a server located at 192.168.18. This server is listening on port 20000 for a connection from my Android application. I am doing this locally for testing purposes.
The Genymotion virtual machine is located at 192.168.57.1, and it does not appear to be able to communicate with the other server.
Is there a way to change Genymotion so that it will operate in the 192.168.1/24 subnet, or a way to get them to communicate properly?

You can easily achieve this. You need to ask your Genymotion device to have a Bridged network connection instead of a NAT.
Open VirtualBox
Select the device you want to see on your local network
Click on settings
Open the Network tab and the Adapter 2
Then switch from NAT to Bridged Adapter
Start your Genymotion device
After that, your local DHCP will handle this new device and give it a local IP. You will be able then to reach you local network from it.
Note: This should be handled very soon directly from Genymotion soft, no need to open VirtualBox for this settings.

Related

How to find specific desktop's ip address on network?

I'm coding an app which consist of two pieces. Desktop and android. There is one desktop and several android devices. (don't know the count.) I want to communicate android devices between desktop with TCP. However, android devices doesn't know desktop's lan ip address.
I thouht 2 ways:
1-Desktop app changes the local ip address on start. So android devices know the ip address. (I coded with that ip address)
2-Desktop app always tries to connect ip addresses (192.168.0.1 - 192.168.0.255) to sent desktop's ip address. And when an android device connect to the network accept the connection then know desktop's ip.
But there is some problems in both ways.
On first, you must be administrator to changing lan ip. So run command as admin with java is a problem. Because if I do this, when user start the program, uac always asks for it.
On second, I think there will be performance issues because of app always tries to connect. Exept this, when android device connect and dhcp gives it 192.168.0.5 , but loop is on 192.168.0.150. So android device have to wait for connection.
Is there a better way than these?
Look at this post Network discovery in Java using multicasting
I think this would be the best way to do it.
The server will listen for a broadcast message from client
the client sends a broadcast request asking for server ip
server receives request and replies back with server ip.
You can use the hostname. If the network is properly configured, the host name will point to the correct ip even if it changes

How to connect Android device to a Java program via sockets?

I need to connect an android device to my java program via socket connection. The device is working as server. The problem is that while trying out socket connection I need to give IP address and port number of server.
Is there something like a static IP address for an Android device to connect? If not, is there any alternative way to establish a socket connection between the device and my program?
As the device has to have a connection to the same network as the computer, it has to have an IP address configured. So you have to use that one.
The used port is defined by the server application running on your device.
If you have the problem that anyhow a normal network connection is not possible, but you have an ADB connection, you can forward local pots to the device and let your server listen:
http://developer.android.com/tools/help/adb.html#forwardports
Over a mobile connection (GPRS, EDGE, UMTS, HSDPA) there will be no practicable way to establish a connection from somewhere to your device (instead you have to do it the other way, while canceling the whole client-server directive), in cause of the used IP sharing. In that case you have a problem of which I'm not aware if it's possible in general, not to mention how you could achieve this.
Otherwise you simply have to configure a static IP for your device when connected to your local network, or you have to evaluate the actual IP of your device every most of the time, while using it with this configuration:
Resolve it by the device itself
Resolve InetAdress from DhcpInfo
Documentation for DhcpInfo
Resolve by using ADB command

How to "deploy" a server so that it can be reached over the internet?

I recently developed an Android application with which the Android device can communicate with another Android device running the application.
The communication works over sockets, therefore I developed a server which i run on my computer.
Here is my problem:
The communication between the devices over the Server running on my PC works fine, as long as all devices as well as the PC are in the same LAN (connected over the same Router for example).
Now I want to get the server online, so that the Android devices can connect to the "online" server and communicate with each other over the server from anywhere.
I simply have no idea of how to get the server online and running. How can I do that?
The main issue is, that I know about Client/Server communication locally, but have no experience in the "online" sector.
It is more a network problem than a programming one. Your server open a socket and therefore is available to anyone able to reach that socket.
You have to do a redirection on your router. The problem is that your machine doesn't have a public IP, only your router has one. So when your router receive a packet on port 21 for example, it doesn't know what to do with it. You have to configure it to say "the port 21 has to redirected to the local IP XXX"
Also the public IP of your modem/router can change, depending on your ISP. If your have a fixed IP, it won't change, otherwise you will have to install a software like dyndns to have a domain name associated with your IP.

Accessing a Java Web Application via Mobile

I have a basic web application written in Java, running on a tomcat on my localhost. Currently it's just a simple application with a single servlet to which I access from my browser.
I want to write a mobile android application which will be the client of my Java web application. I want the servlet to write to a DB and do some logic, but to access it from a mobile app.
Currently I don't have any domain registered.
How can I expose my Java web app so that in my development environment I would be able to access it via my mobile device? Meaning, currently it runs locally on my PC and I access from the browser (on localhost). I want to access it from a different device (mobile) - how can it be done in my home LAN?
Thanks.
If the web app is hosted on your local server, your mobile will need to be able to access the IP address (ie: 192.168.1.100) and port (ie: 8080) that is hosting the app.
There are several ways to allow your mobile to communicate to your desktop:
Direct connection via USB or Bluetooth.
Wireless connection on your LAN - if your mobile can connect
wirelessly to your home LAN, you should be able to access your web
app (your desktop's firewall may have to open up your web port)
External access. This requires opening up your home network to allow
access to your desktop's web port. Also your internet router would
have to be configured to allow access and likely do a NAT
translation. Note that in this scenario, anybody can access your web
app so be very careful. You would also need to use your external IP
address instead of your internal LAN address.
A domain is only required to allow the use of a name (http://www.example.com) instead of your IP address.
For testing, if your mobile device is on the same LAN as your server, just use the servers ip address on the LAN. Give the server a static ip address and your sorted.
For the next stage of testing, you'd need to expose your pc to access via the Internet. You'd usually do this by configuring your NAT settings on your home router. You should be able to google this.
Then your mobile device can use 3G and should talk to the server via your ISP ip address. This will hit your router and the NAT routing will forward it to your server machine on your LAN.
If you need any clarification, just ask !

Java application on Windows system running as USB peripheral

Is there a way to have a USB device act as a Host and an application on a Windows based system to act as the Peripheral? We have a USB device that is the host and we need it to connect to our application running on a Windows based system. The device is using USB 2.0 On-the-go specification, but it needs to run in Host role. We have found a few libraries and what not but they seem to only work if the application is host and the device is the peripheral. Any information or leads would be greatly appreciated.
Thanks.
The USB Ports on a typical Windows PC can only talk in Host mode. This means that if your device is directly connected to a PC (including hubs), it has to run in device mode.
There are devices that can talk to 2 USB hosts at one (e.g. some USB<->USB PC connection cables). That could be one solution to your problem, but to me it looks more like you just have to adapt your devices software some bits.

Categories

Resources