learnscript has asked for the wisdom of the Perl Monks concerning the following question:

I need to implement a simple proxy server in perl in order to test a client program, which talks to a server in certain text based protocol(RTSP). What I want is simple:
1. the proxy should bypass the setup/teardown request to the server.
2. for non setup/teardown messages, the proxy should be able to modify the server's responses and then send them back to the client in order to test different possible secnarios, which may be hard to see with direct client-server communication.

Does anyone know of any code sample of a proxy server in perl? Or, any suggestion on where to start? I know perl, but I havent' done any network programming with threads. Thanks.

Replies are listed 'Best First'.
Re: coding a simple proxy server in perl
by chromatic (Archbishop) on Sep 22, 2006 at 06:26 UTC

    You don't mention which protocol you use, but any of HTTP::Proxy, Stem, or POE might be a place to start. I'm not sure anyone can be of more help without more detail however.

      It's RTSP(Real Time Streamming Protocol), which is text based.
      Thank you.
Re: coding a simple proxy server in perl
by learnscript (Initiate) on Sep 23, 2006 at 02:26 UTC
    POE seems to be the way to go.
    The code samples from http://poe.perl.org/?POE_Cookbook/TCP_Port_Redirection seems to be what I have been looking for.
    However, I am having problem with the forwarder_server_input function. The server can receive request from the client, but the client cannot receive the response from the server. The TCP_Port_Redirection script(my proxy) does receive and attempt to pass the response message to the client. Any suggestion?
    # The forwarder has received data from its server side. Pass that # through to the client. sub forwarder_server_input { my ( $heap, $input ) = @_[ HEAP, ARG0 ]; print "Received the following data from the server and attempt to +send them to the client\n"; print "==\n$input\n=="; #this is the response from the server, but + the client somehow can't receive it. exists( $heap->{wheel_client} ) and $heap->{wheel_client}->put($in +put); #maybe the wheel_client object is gone? If so, how do I keep it a +live? }
Re: coding a simple proxy server in perl
by learnscript (Initiate) on Sep 23, 2006 at 07:40 UTC
    Hmmm, I guess I have found the problem, though not sure why.
    $heap->{wheel_client}->put($input)
    returns zero.