I have small TFTP server running on port 8080. It is an Android application. When I try to connect it while being on Ethernet, it works seamlessly. However, when I switch from Ethernet to Wifi. I get 'Connection refuse' error. Or sometime it displays first page and then when I try to navigate, it crashes with same error. So, what do I need to do if the IP changes ? Do i need to restart the TFTP server ?
Thanks
This looks like a wifi network error due to some radio interference or to some problem with the hardware. The connection refused error is probably the effect to some timeout that get triggered on after a (partially) failed attempt to establish a communication channel. This is why you sometime can see a part of the requested document.
I'm almost sure you are using a wireless router to allow the two device to communicate each other. Did you try a different router and/or a totally different place (a friend's house, for example)?
Related
I've installed sl4a and Python on my Android-powered Galaxy Tab. I've run into problems using python's socket module to communicate between my laptop and my phone.
This example had always worked fine for me when I'd been writing computer-only python programs, but doesn't work as expected on a computer/Tab set-up. Here is the code I'm running on the Tab:
import socket, android
droid=android.Android()
droid.makeToast('Running...')
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 50111))
droid.makeToast('Socket has been bound')
s.listen(1)
conn, addr = s.accept()
droid.makeToast('Connection has been accepted')
And the code I'm executing on the laptop (where <Tab IP Address> is the IP address of the Tab):
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('<Tab IP address>', 50111))
The client script (on the laptop) errors with:
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
And the script on the Tab displays all but the last Toast message.
I'm getting the IP address of the Tab from www.whatismyip.org.
Local socket programming (i.e. connecting to IP address 'localhost' and running both client and server on the Tab) works fine.
I've been using the guide here to transfer files to my Tab.
For context, the final desired goal of my project is to be able to send a text via my Tab by executing a command on my laptop. I'm sure solutions already exist, but I'd like to learn how to do it myself!
EDIT: [Added 21/03/12] It turns out that the code above works fine (communicating between Tab and Laptop) if I connect the Tab to my wifi network and use the 192.168.0.xx address. This leads me to believe that the problem lies with the IP address I'm using to connect to the Tab, rather than the code itself. I'll keep trying. Any advice on the best way find the IP address to connect to, or errors I might be making, would be appreciated.
EDIT AGAIN: From reading this question and this link, I've concluded that smartphones' (and tablets') IP addresses are not static, and so treating the mobile device as the server in this situation is the wrong way to do it. I'll rethink my program structure.
Although I know now that this was the wrong way to structure the interaction, I still don't entirely understand why it failed. I suspect, from reading the earlier links, that the IP address I was getting from www.whatismyip.org wasn't unique to my Tab, but was rather a "bulk IP" belonging to my network provider, from which connections can then be forwarded on to individual devices (in the same way that a network router can forward connections to itself on to individual devices on the network). However, I'm not certain of this, and can't think of any way to verify it (short of hunting down people on the same network as me, who live in the same cell area, and asking them their mobile IP's). If someone could clarify this point, I'd be very grateful.
You were right about the "bulk IP" thing. When you're connecting your phone through wi-fi it will get a random IP from the router's available IP address pool.
It usually gets the same IP if you have a constant number of devices connected to the router. For example if you have 3 computers connected through cable and 1 smartphone then the phone will always get the 192.168.1.5 IP (192.168.1.2 - .4 IPs are used for your computers).
Depending on the router you have you can set it up to give the exact same address to your smartphone every time you connect it to wi-fi. And the IP you were using from www.whatismyip.org is the one from the provider, which a network uses to reach "public internet" (but that's another story).
You should check your local IP that's on your tablet (Settings->Wi-Fi->Wi-Fi settings-> and press the connection. A small info box should appear with your IP).
You should use that in your code for the server.
I hope this helped.
All of the documentation, examples and questions I've seen so far on TCP connections with Android have been between an Android device and a computer. As unreliable as wireless can be, is it possible to make a client-server TCP connection between Android devices over WiFi, and if so, how?
Edit: I guess I should elaborate more on my situation.
My Droid does not respond to ping or accept incoming TCP requests from anything unless I first make the Droid a client and my laptop the server. After this initial connection is established I can then ping from my laptop, or make the Droid a server and my laptop the client. What I can't do is make one Droid the server and another a client, I always get a "No route to host" error.
It feels like there is something blocking incoming connections unless the device initiates a connection to something else, and even then the only request the device will accept is with this device. How can I make my Droid a server that accepts all incoming TCP requests from any device on my local intranet?
You should be able to. Just do like you would do with computer/device connections, except run the client and server code on the devices.
One of the neat things about the Internet is that the Internet doesn't care whether you are establishing a connection between two PC's, a PC and a phone, or two phones. I would look at the Socket documentation, that should be enough to get you rolling.
It's certainly possible. The only problem is figuring out the IP address. I don't expect a phone have a fixed IP... However, if there is a fixed "login" server somewhere in the Web which IP is known to both phones then they can do a handshake via that server and after that continue peer-to-peer.
re; The only problem is figuring out the IP address. I don't expect a phone have a fixed IP.
Try this;
Use the web browser on the phone to log into this website: It should provide you the IP address.
http://whatismyipaddress.com/
I'm designing an Android app that will require the use of a web server on the local device. I've been trying out some different servers for this purpose. At present I haven't written any code or run anything in an emulator, just played around with the servers on my actual phone, and I'm observing some strange behaviour.
Whenever I try to connect to the local web server, and I have WIFI switched off, the HTTP request fails. If I switch WIFI on, it succeeds.
Depending on which address I use, I get different results: using localhost or 127.0.0.1, I get connection refused when WIFI is off; using the current 10.X.Y.Z address I get a timeout. Both addresses work when WIFI is on.
I have tried this with xWS, PAW and i-Jetty: the behaviour is consistent. WIFI on, I can connect to the local web server; WIFI off, I can't.
I am using the default "Internet" browser on Android 2.3.3 on a Samsung Galaxy S (GT-I9000).
Does anyone know why this is? Is it a simple question of a setting somewhere I need to change, or what's going on?
Cheers,
/Uffe
Can you change the network interface the web server is connected to?
The default setting is probably something like eth0 or wlan0, if you change it to lo it could work.
You are asking why when you turn off your wifi, there is no connection to the 10.0.0.2 (Your computer's localhost) and when you turn it on, there is a connection?
Very simple. Wifi off - NO INTERNET connection. The device emulator is a separate OS inside your computer's OS. When you turn off your WIFI there is no route to the host (your computer) - there is no internet
I have now tested with my own simple client, and with Opera - and it works.
So in fact this is an issue not with the IP stack but with the default Android browser, or possibly with the settings enforced by the manufacturer (Samsung) or carrier (Telenor Sweden). Either way there is a workaround: use Opera instead.
Still don't know why it doesn't work with the default browser, but I'll mark this question answered.
I have an android application that talks to a server app running on grails (Groovy on Grails).
Android app basically establishes a connection with this address:
url="http://192.168.2.53:8080/tma/majBtm/androidToDesktop";
It all works fine when both the server and the android phone are connected in the same lan network.
Now the problem arises when I want the phone to talk to the server while the phone is outside the local network (I need it to use edge).
I came across VPN networks which I think might help me out. (the server has dynamic IP)
So what i did was go to dyndns.com and created a new hostname and have the app successfully run on the server. The host I created was - tmagrails.dyndns.com
How do I make my phone connect to this network? What changes am I supposed to make in order to get things working?
Also, I really want to know if this is the right approach. If not, is there any way to get things going for me?
Please advice.
First you need to set up port forwarding so that port 8080 is forwarded to your 192.168.2.53 ip address. A google search on your router model should tell you how to do this. If you want to make your app more secure you will also need to look at SSL and TLS While this won't garantee your app is secure it will stop the network traffic to your app being easily read if you were to access it from an open wifi hotspot.
I am developing an android application where i need to connect to a server socket from my application. The application works fine when i am at home and my android phone and the server using the same Wi-Fi. However, when I am at the university my application can not connect to the server socket. It always shows "The Operation has timed out Error".
Obviously I have changed the code to make sure if i am connecting using the right IP Address.
Can anyone give me some suggestions please.
thanks
kaisar
If it's working fine at home, but not other places, it would lead me to believe the wifi you're connected to at school may be blocking people from accessing other sites on certain ports. This isn't uncommon. If you're not using wifi, your wireless provider may be doing the same thing.
When you're at home, try turning off wifi and going through the cell network and see what results you get.