Interactive socket connection
Rayed Al-Rashed
rayed at saudi.net.sa
Sat Jun 1 05:10:51 EDT 2002
Hello,
I am trying to build POP3 proxy, I want it to run from "inetd" so it should
communicate with the user using regular stdin, stdout.
I built a small code that should run as general proxy for any protocol, but
I faced the following problem, it doesn't show any output from the server
until I pass it a command, for example:
-----------------------------------------
user rayed
+OK POP3 pop.mydomain.com server ready
pass mypass
+OK User name accepted, password please
rert 1
-ERR Bad login
quit
-ERR Unknown AUTHORIZATION state command
+OK Sayonara
-----------------------------------------
Any ideas what the problem is?
Thanks in advance,
- rayed
This the proxy code
--------------------------
#!/usr/bin/python
# POP3 proxy
import sys
import string
import socket
import asyncore
import select
class proxy (asyncore.dispatcher):
def __init__(self, server, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
self.connect ((server, port))
def handle_connect (self):
pass
def handle_read (self):
buf = self.recv(8012)
sys.stdout.write( buf )
def handle_write (self):
buf = sys.stdin.readline()
self.send(buf)
def handle_close (self):
print "Closed"
if __name__ == '__main__':
p = proxy("pop.mydomain.com", 110)
asyncore.loop()
More information about the Python-list
mailing list