python - blocking recv() returns empty line instead of actual data -
i'm working on python client supposed converse c programmed server. answers few recognised commands "ok" (the server part works when test netcat client). python client gets ok 1 out of 4 times (and empty lines rest of time). don't why socket set blocking figure receive don't know what.
here have. "info" object few strings stored in it, before loop works , bit simplified readability : i'm supposed receive welcome message send team name of connected player receive position.
try: s = socket.socket(socket.af_inet, socket.sock_stream) except socket.error, msg: print 'failed create socket. error code: ' + str(msg[0]) + ' , error message : ' + msg[1] sys.exit(); try: remote_ip = socket.gethostbyname(info.host) except socket.gaierror: print "hostname not resolved. exiting" sys.exit() s.setblocking(1) s.settimeout(60) s.connect((remote_ip, info.port)) data = s.recv(1024) print data team = info.team + "\n" s.sendall(team) data = s.recv(1024) print data while 42: msg = raw_input('>> ') s.sendall(msg + "\n") data = s.recv(1024) if data == "": break else: print data s.shutdown(socket.shut_wr) s.close()
it seems me receive : cast data ascii ord() see it. guess there's 3 unprintable lines before "ok" in response server sends you. identify catch them in new loop.
Comments
Post a Comment