socket.error: [Errno 99] Cannot assign requested address

0 Tony Stark · July 9, 2015
I just started learning about networking and created a simple TCP client server network. Initially I used as host and 5000 as port and the programs I wrote in python were working perfectly. However I went into android and tried to connect to the server however the android emulator I'm using has a localhost with ip = which meant that I had to change the host's ip address in my server. However it doesn't matter what ip I change it to I get the error in the title. I've tried and several others. Can someone point me in the right direction please

Post a Reply


Oldest  Newest  Rating
0 Rehman . · July 9, 2015
could you please paste your code here?
0 Tony Stark · July 9, 2015

import socket

def Main():
#host and port
host = ''
port = 5000
#create socket
s = socket.socket()
#bind socket to a port & host
#start listening for connections
#1 connection at a time
# accept function that returns a connection
#which is a new socket
c, addr = s.accept()
print("Connection from", str(addr))
#talk to client
while True:
#receive bytes from connection
#max buffer = 1024 bytes
data = c.recv(1024)
#if client ends connection so no data, break
if not data:
#print to sever data from user
print("from connected user: " + str(data))
# we can do whatever we want with the data now
#exaple turn it to upper case
data = str(data).upper()
print("sending: " + str(data))
#send the data
#after connection is closed

Android Code

URL url = new URL("");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

//read the response
InputStream in = new BufferedInputStream(conn.getInputStream());
String response = in.toString();

The host and port,5000 only works when I run the server and client in python on my laptop. However the same ip address is the localhost for the emulator I'm using for android so it doesn't work, I have to change it. However It doesn't matter what new ip and port I change the server to, I get the error above when I run the server code. I tried' and port to 6677 but nope, same error
  • 1



Chat about routers, switches and firewalls, and more!

Bucky Roberts Administrator