Question

I have an android phone running a client.py and a server.py running in my computer. My computer's ip is set to 192.168.16.7 (running ubuntu 13.04. Did it in the network manager) and my phone's ip is set to 192.168.16.9. I created a wifi hotspot using my phone and tethered my computer to it. This is my server.py:

import socket
s=socket.socket()
port=12345
s.bind(("192.168.16.7",port))
s.listen(5)
while True:
  c,addr=s.accept()
  print "got connection from ",addr
  c.send('Thankyou for connecting')
  c.close()

And my client.py is :

import socket
port=12345
s=socket.socket()
s.connect(("192.168.16.7",port))
s.send("Hello world")
s.close

server.py runs in my computer and client.py is in my phone. But when I try to run client.py in the phone, it tells me that the network is unreachable. How do I fix this?

Was it helpful?

Solution

Fixed it. The problem was with the static ip that was set in the phone. Even though I had set the static ip of the android phone to 192.168.16.9, it was not so. To check this, go to sl4a->view->interpreter->shell and type 'netcfg' and press enter. Among the various things that appear i found that the ip written corresponding to 'wlan0' was 192.168.43.1. So I set the static ip of phone to the above ip and then changed my computers ip to 192.168.43.8. So the server should bind to s.bind(('192.168.43.8',port))

And the client should connect to the same address.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top