I am trying to create a P2P network of android(V3.2) devices to share information like news,updates between them .
Been trying TomP2P, how ever am not able to find a solution of how to debug these . For example I would like to run two different instances either in emulator or AVD Manager and to get these messages shared in between them.
Have also tried port forwarding,how ever yet to see how to communicate between these two emulators.
Any suggestion will be much appreciated.
You need to setup port redirection as described here. Lets assume you have two emulators listening on the default port 5554 and 5556:
Since TomP2P uses UDP and TCP, you need to redirect both on both emulators:
telnet localhost 5554
redir add udp:5001:4001
redir add tcp:5001:4001
and
telnet localhost 5556
redir add udp:6001:4001
redir add tcp:6001:4001
This will redirect from your developer machine (10.0.2.2) port 6001 resp. 5001 to your Android device to port 4001. To connect from one Android device to an other Android device you have to use the IP 10.0.2.2! Further details with a working example can be found on the TomP2P documentation site.
Related
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
I'm developing multiple applications which need to communicate with each other via socket. First I need them to be able to communicate on localhost. So when I'm running both of them at the same time on my phone they can communicate (I know that there are easier ways to do this on the same phone but in the future they will run on separate phones).
My code for socket communication is very similar to this: link
Difference is that my apps are running this as foreground services.
I've set the ip for the server on the client to 127.0.0.1 but they just won't connect (not in the emulator and not on real phone). What am I missing?
UPDATE:
I've found an easy way to get the device own IP address, so instead of localhost I use this (with www.google.com domain): answer to "java InetAddress.getLocalHost(); returns 127.0.0.1 … how to get REAL IP?"
Maybe it's not too nice but it works.
You'll need to set the local IP address of each one, so they can communicate within your LAN. So use an address like 192.168.1.X. Both if you're running your devices as virtual or physical, you may easily know the local IP address they have accessing your router's web interface and seeing their bound IPs.
I have an application made of a device I made to connect through USB emulating a Serial port. Now, I need to connect the same device via bluetooth so I'm using a RN-42 (Bluetooth to serial port) in my device to send the data over RF.
Then I pair my device in Windows with the laptop's internal BT module which creates to COM ports a Outgoing and a Incoming one. Then if I connect using Br#ay's terminal I receive the expected data when I connect to the Outgoing COM port.
The problem is that when I use my Java app where I am using the last RXTX libraries, I can discover the COM port (which is the problem that everyone has, at least thats all what i found in forums) and it seems to connect but then I don't receive no data. Using the same exact program but connecting using a cable it works just fine as the terminal does.
I also tried to use the BlueCove libraries, I can find the bluetooth devices but I don't really know how to discover it services and then connect to it using RFComm. I can't find a complete example of how to do that.
Any help will be appreciated!
I'm getting similar problem with default Windows Bluetooth stack.
With Toshiba stack communication is ok.
I want to build a ring topology using android emulators.
Currently my application has both client and server.
How can I run the same instance of my program on different emulators?
i.e. how to set the re directions on different emulators (redir add ?)?
Can anybody give me some pointers regarding this.
Assuming that you are running your app from Eclipse you can go to the menu "Run" > "RunConfigurations..." This will show a window with all the available configurations. Select the one from android that you want to run on different emulators and select the tab "Target".
Once in there select Manual instead of Automatic. This will prompt you where you want to deploy. You may have to create more than one AVD so you can launch more than one emulator.
It can be built by making connection to all emulators provided we redirected all the emulator port to same port.
for example :
if we want to connect 3 devices in ring passion
we have to set up one redirection to server port for each emulators
2.i.e redir add tcp 4444:8000 redir add tcp 4445:8000 redir add tcp 4446:8000 in 3 diff emulators.
2.create server on each emulator at 8000 port.
3.connect to port 8000 from all the emulators.
My machine is running on window 7.
I want to communicate between two android emulator's running on same machine.
Emulator first is listening on some IP 10.0.2.15
When second emulator tries to create
Socket socket = new Socket ("10.0.2.15",8080);
It gives exception, unable to connect to 10.0.2.15
does any one know how to solve this problem?
EDIT: I've already read https://developer.android.com/studio/run/emulator-networking#connecting but it says
On B's console, issue redir add tcp:8080:80
What does it mean by B's console, or where is B's console??
What you need is to install TELNET on your Windows 7 machine. For that, Control Panel -> Programs and Features -> Turn Windows Features On or Off -> Telnet Client (must be ticked).
Then, in cmd (command prompt), you can say adb devices (if the Android SDK is on your PATH), which returns identifiers such as emulator-5554 and emulator-5556.
Now with telnet, you can access them with telnet localhost 5554 or telnet localhost 5556.
To get them to tell you which emulator it is, you can type avd name.
But more importantly, it tells you this:
Android Console: Authentication required
Android Console: type 'auth <auth_token>' to authenticate
Android Console: you can find your <auth_token> in
'C:\Users\[youruser]\.emulator_console_auth_token'
OK
Which is a text file that contains some random cryptic text.
You can copy paste that into the telnet like so:
auth cdPi82HewjZg
to which it will say OK, now you can actually run the command the documentation said.
Now you can say
redir add tcp:6000:4000
Which means: if the emulator would receive something to Port 6000 from LocalHost, then it should receive it as 4000
Which means your other emulator can connect to it through the 10.0.2.2 magic loopback IP by sending data to 6000, and it is the other emulator that will receive it, with port 4000.
It also works not just for tcp: but also for udp:.
You can list redir and even remove redirections with redir del.
There may be two reasons
As per my knowledge is concerned you have run is < 2.3 version
Add Internet permission
Try to run the server first say in emulator number 5554 and client (say) 5556
then type
telnet localhost 5554