Reputation: 11
I have a ploblem with socket communication in my python app. I'm using python32. OS windows 7. In my task i must use UDP sockets. If i ran my app from IDE(Eclipse) communication between client and server is fine.
BUT: if i ran my app in Command Promtp and then i can't to communicate from client to server (get errno 11004 getaddrinfo failed). On windows xp app work fine. I'm trying to turn off firewall but it doesn't help. Why i can't communicate from cmd?
Client connection:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(15)
except socket.error as msg:
print(msg)
s.close()
s = None
addr=(HOST,int(PORT))
msg="CONNECT"
s.sendto(bytes(msg,"ascii"),addr)
try:
data = s.recvfrom(1024)[0]
except socket.timeout as err:
print("Connection lost! /cry")
sys.exit(1)
and server code:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error as msg:
print(msg)
s = None
s.settimeout(45)
s.bind(('0.0.0.0',PORT))
if s is None:
print('could not open socket')
sys.exit(1)
print("Server created. Waiting for player.")
sost = "Server"
while True:
try:
(data,addr) = s.recvfrom(1024)
except socket.timeout as err:
print("Nobody want's to connect! /cry")
sys.exit(1)
if data == b"CONNECT":
print("User from {0} connected".format(addr))
s.sendto(b"CONNECT_OK",addr)
break;
PS: Sorry for my english :)
Upvotes: 1
Views: 2149
Reputation: 178
can you print out the value of the addr variable when you get the exception? maybe something silly with the address (embedded line feed or something like that)
Probably safest to add a addr.strip() call?
Upvotes: 1