I am going to create a SOCKET connection between 2 EMULATOR, i have the below code but Nothing happens. The Server class returns me this Ip address:
10.0.2.15
and i am using this in my Client Class but nothing happens, i am not getting message at server
I am using the code for both server and client from this link Socket communication between two apps on Android
please help me, i have the same code as in the above link, and i am using 10.0.2.15 in Client to connect with server
Actually the Emulator have no ip address, it always contain this type of Ip address "10.0.2.15" which is in fact can't be access from Mobile phone or other devices, because it is an emulator. in contrast the emulator can send a connection request to other server like my Mobile whose ip address is "172.23.0.101", So in this case connection will be established between emulator(as client) and Phone(as Server).
In my project i have this ip address and it works well
Mobile Phone IP Add: 172.23.0.101 (SERVER)
Emulator IP Add: 10.0.2.15 (CLIENT)
Okkkkkk !!!, i solved my problem.I am sending messages from Emulator client to My mobile device where i have run the server program. My mobile device ip is
192.168.180.101
So, i am using this IP Address in client program and sending sms from client to server successfully.
The problem that you couldn't connect tow android emulator instances together via TCP is that they both run on a separate subnet.
Android documentations cover this topic in details and provide solutions for cases where you want to connect different emulator instances together, you can see it here: Android emulator Networking
Also there were couple of questions that are similer to your question:
here and here .
Related
What I am trying to do is make an Android App for my NodeMCU so that I can send data via Websockets and not use the browser. I don't want the end user to be inputting any IP addresses to look for the NodeMCU in the network. I understand that you can set a hostname for NodeMCU.
Is there any way I can get the IP of the NodeMCU in the network using its hostname and then further communicate over it?
You can find ip of server without using its hostname.
Both devices run in the same -wifi- network.
The Android client knows its ip. Say 192.168.2.12.
Now it knows that the ip of the server will be like 192.168.2.##.
Just make a loop where you use a Socket that tries to connect using ip's around the one of the client.
Set a socket time out of two seconds or less.
I want to test my ejabberd (xmpp) server, which I've hosted on my laptop, which is working on windows 10 based OS. I want to connect my android client to this server. So I went on to the internet, and found some solutions. But they seem don't work for me. This is what I've tried:
1.) Create a hotspot on a phone. Don't use data/wifi connection, as server is already on the machine.
2.) Connect the laptop to the hotspot.
3.) On cmd (running as admin), type 'ipconfig', after starting xmpp server (Obviously).
4.) Copy IPv4 address (External IP), and access web panel on the mobile browser through it.
So, I hurried toward my phone, and typed
http://[IPv4 Address]:[port open on the server for incoming connection/5280]/admin
But it(browser) throws 'Can't reach the webpage' error.
When I run
http://localhost:5280/admin
on my laptop, I could easily access my web portal, but It's unreachable on my android phone. What can I do now?
Well I solved this problem by accessing IPv4 of my laptop through my wifi router, and connecting to the port of my server through it. Initially, my browser (both of my laptop and my phone) weren't able to reach the server's port. But I later figured out it was problem in my .yml configuration file. Server wasn't set to listen all the IPv4 calls, instead it was listening to all IPv6. So I changed this, and it then become accessible to all devices on the same wifi. So it was my bad idea to connect it through the hotspot :P
I am struggling with this for three days now. It is an android client application that connects to the server AIR application through Wifi on local network.
I need my application to connect to the server every time it is launched without asking the user to enter local IP, in case it changed.
It seems there are many ways to make sure the connection is successful, but I want to make sure I can go without the help of RTMFP or PHP or SharedObject stuff.
I am able to get local IP using NetworkInterface and NetworkInfo ANE from Android client. Then I use the variable to
mySocket.connect(ipAddress, 8888);
But there is a problem:
1) When debugging on Android via Wifi
The detected IP 192.168.137.2
2) When debugging on Flash, on computer
The detected IP 192.168.137.3
So, the local IPs are not the same. So client fails to connect. Everything works perfect, if I manually set that IP, but I need a code that works, even if the IP on local network changed.
As I mentioned making a textInput field in case IP changed and ask the user manually enter IP is not an option.
My question is why using "localhost" as host parameter of socket.connect(host, port) does not work? If it did, there would be no need for detecting local IP at all. "localhost" works for me only if the client is running on computer, but not Android.
Is it the problem with Security Policy file? if so, I have no idea how to use that. I can't find any tutorial on that.
You have two devices
1. Android device running an app and acting as a client
2. Computer running an AIR app and acting as a server
Each of those devices will have it's own IP address on the network. In your case android device IP is 192.168.137.2, and computer IP is 192.168.137.3.
In order for client to connect to server there must to be some means of delivering server IP to the client. Normally for an app like this you enter server IP address manually in settings, or have one central place available on the net where server registers it's IP address and client fetches the address from there.
Since you don't want to use any of these options the last resort would be implementing local area network scanning. Where you scan all the segment 192.168.137.* and search for opened port reserved for server. That of course is not good implementation but could work if project is for your own use.
Lastly "localhost" is name mapped to loopback IP 127.0.0.1 which is special address and is used to connect to the same device app is running on. In your case if android app is connecting to localhost it is trying to connect to the android device itself.
I have a client application which is currently able to communicate to the server from android emulator.
It does not work if I run it from my android phone. What could be the possible issue..??
Note: Its a socket communication and I am using AsyncTask for the same and ensuring that I am not running in the main thread.
IP address and the port numbers are still the same.
If you use socket communication by using your mobile , you should check whether your server ip is public ip that you can access in anywhere or not. unless ip address network is different between server and client (your mobile), It would run very well~
I'm developing an application that need an internet permission all the time.
When there is a WIFI connection the application can connect to my server (if they're in the same network)
actually I have 2 question..
1) Lets say that the server is connected to network A and the client is connected to Network B (on
WIFI) why it doesn't show me on the server side the message that I send?
I made a simple project that when the client is connecting to the server it send "hello" to the
server, the server read it and tell me the address of the client and the message (print to the
console), it works fine when both server and client are at the same Network.. but when they're in
different networks it doesn't work.
2) How a 3G application is working? how can I connect the client who uses a 3G network to my server?
When you are on the same network then you give the the ip the ROUTER gave to your pc and phone (assuming that what your using) and it looks something like 192.168.0.101\2 (its your router Default address + 1 each time a device connects to the router) ...
The problem is that when you want to connnect from an outside source you must give the ip of your real address given by your ISP.
go to command\terminal and type ipconfig and look for IPv4 ------ thats your real ip when looking from the "outside" world , now thats not all you also need to configure your router to port forwad the ports your using to the specific PC that is the server.
How what and why : Port Forwarding
hope this helps.