python socket proxy

jstobbs at gmail.com jstobbs at gmail.com
Tue Jun 6 03:11:59 EDT 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 (127.0.0.1). 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 127.0.0.1. 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

[code]
# Echo server program
import socket

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


# Echo client program
import socket

HOST = 'remoteserver.com'    # 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
s.close()
print 'Received', repr(data)
[/code]

thanks




More information about the Python-list mailing list