[Tutor] View pop3 commands/responses script - part II
Steve
slyskawa@yahoo.com
Fri, 22 Mar 2002 21:32:12 -0500
Okay, I figured out my problem, I was using bind instead of
connect. Now I need a way to detect if the connection went away.
I could use some pointers on blocking versus non-blocking IO and
how I could use it to my advantage in my program. Here is what I
have.
Thanks,
Steve
___________________________________________
from socket import *
import string,time
local=socket(AF_INET,SOCK_STREAM)
local.bind(('127.0.0.1',110))
local.setblocking(0)
local.listen(1)
addr=0
while not addr:
try:
conn,addr=local.accept()
except:
pass
print 'ip,port ',conn,addr
conn.setblocking(0)
remote=socket(AF_INET,SOCK_STREAM)
remote.connect(('popmail.com',110))
remote.setblocking(0)
count = 0
while 1:
try:
rdata=remote.recv(2048)
print '<== Data Received'
print rdata
conn.send(rdata)
except:
try:
sdata=conn.recv(2048)
print '==> Data sent'
print sdata
remote.send(sdata)
except:
time.sleep(1)
pass
local.close()
remote.close()
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com