Well, these things, and I used to see the kernel when the east, corresponding to the.
Select,poll,epoll, non-blocking, asynchronous, etc...
But I didn't tune it out. You can take a look when you are free to go home, no more banging the code ...
#!/usr/bin/env pythonImportsocket, sys, Selectport= 54321Host='127.0.0.1'spinsize= 10Spinpos=0spindir= 1defspin ():Globalspinsize, Spinpos, Spindir spinstr='.'* Spinpos + '|'+'.'* (spinsize-spinpos-1) Sys.stdout.write ('\ r'+ Spinstr +' ') Sys.stdout.flush () Spinpos+=SpindirifSpinpos <0:spindir= 1Spinpos= 1elifSpinpos >=Spinsize:spinpos= 2Spindir=-1s=Socket.socket (socket.af_inet, socket. Sock_stream) S.connect ((host, Port)) P=Select.poll () P.register (S.fileno (), select. Pollin| Select. Pollerr |Select. Pollhup) while1: Results= P.poll (50) iflen (results):ifRESULTS[0][1] = =Select. Pollin:data= S.RECV (4096) if notlen (data):Print "\rremote end closed connection; exiting." BreakSys.stdout.write ("\rreceived:"+data) Sys.stdout.flush ()Else: Print "\rproblem occurred; exiting."sys.exit (0) spin ()
In a poll way, without running out of results, Licicunzhao