python socket proxy

jstobbs at jstobbs at
Tue Jun 6 09:11:59 CEST 2006

Hi all

I am trying to create a lighweight tcp proxy server.

I got this code from ActivePython documentation.
What I am trying to accomplish, is I need to connect to local instance
of the proxyserver ( This server must then connect to a
remote jabber server, send data, and listen to incoming data. When data
arrives, it must relay it back thru The reason why I need I
am trying to get this to work, is I eventually want to make this server
connect over ssl/tls (which macromedia flash doesnt support natively).

The existing code only echoes back what it gets in, and note what it
gets back from the remote server. Help would be appreciated

# Echo server program
import socket

HOST = ''                 # Symbolic name meaning the local
PORT = 50007              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    print (data)
    if not data: break

# Echo client program
import socket

HOST = ''    # The remote host
PORT = 5222              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
print data
print 'Received', repr(data)


More information about the Python-list mailing list