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

I'm about to start working on a GUI client for a server app which is written in Python but I'd like to use Perl for the GUI. I'm currently looking at using Tk due to the excellent amount of reference material out there (as opposed to something like wxWindows). The one thing I'm getting stuck on is the method of client-server communication.

I know very little about SOAP, RPC, and the like (those terms could even be redundant, I wouldn't know). What I'm looking for is something similar to query strings from HTML forms - with two exceptions: 1. I'm going to be encrypting all transmitted information and 2. I'd like to avoid the messy character escaping. Sorry for the vagueness but I only have half an idea what I'm doing ;-)

My question to the monks is, what have you found to be the most effective method for sending moderate amounts of encrypted text data from a GUI client?

  • Comment on Distributing Perl GUI Clients for Server Apps

Replies are listed 'Best First'.
Re: Distributing Perl GUI Clients for Server Apps
by benn (Vicar) on Aug 06, 2003 at 11:34 UTC
    What you're talking about is simply 'protocol'. As you control both sides of the communication, you can use any protocol you like - making one up to suit your needs would probably be as easy as bending another (HTTP, SOAP etc) to fit.

    If, for instance, you're wanting to send a number of encrypted key-value pairs, this could be as simple as

    use Crypt::Simple; print MYSOCKET encrypt(join(":",map {"$_=$vals{$_}"} keys %vals));
    ...and a quick split/map/decrypt on the other end will reproduce the hash.

    RPC (and thus SOAP) is more often used where you're sending 'objects' back and forth, allowing a client to perform Remote Procedure Calls...overkill for simply sending 'data'.

    Having just knocked out a moderately-sized wxWindows app btw, I can (charitably) say that the documentation gives you just enough (with a couple of very minor errors / omissions), and I'd definitely use it again for all my advanced GUI needs. :)

    Cheers, Ben.

      So would I just be looking at something like IO::Socket? I haven't done much (read: any) socket programming before, any guidance is appreciated.

        Oh - sorry - you're *not* just talking about protocol... :)

        IO::Socket is the OO version of the basic 'Socket' module - you can use either, though it's usually easier to use the first to do something like below...

        A client...

        use IO::Socket::INET; my $socket = IO::Socket::INET->new("${my_server}:${my_port}") or die $ +!; print $socket "My Ping\n"; my $answer = <$socket>; #should be 'My Pong' close $socket;
        A server...
        use IO::Socket::INET; my $server = IO::Socket::INET->new(LocalPort=>$my_port,Type=>SOCK_STRE +AM,Listen=>1) or die $!; while (my $client = $server->accept()) { my $message = <$client>; print $client "My Pong\n" if ($message =~/My Ping/); }
        ...which is obviously not going anywhere near production code, but should be enough to get started with. Check out the 'Sockets' section of the Camel Book for more info.

        Cheers, Ben.

Re: Distributing Perl GUI Clients for Server Apps
by zby (Vicar) on Aug 06, 2003 at 07:47 UTC
    The simplest method would be to use a web browser and HTTPS. Of course this would a bit constraint the GUI (until perl XUL library is ready: there.is.only.xul).

      Hi, sorry I should have specified that I want to avoid web browsers. Their simplicity can't be beat, but unfortunately they have many limitations as well. The GUI would need to do semi-advanced text editing (amoung other things) which <textarea>'s just can't do. Thanks anyways for the suggestion :)

Re: Distributing Perl GUI Clients for Server Apps
by Zaxo (Archbishop) on Aug 06, 2003 at 13:58 UTC

    It sounds like a remote X connection through ssh would do everything you want. That would give you transparent encryption and control of the client application, which would run on the server. The only disadvantage is that winders boxes generally lack ssh and X, though both are ported, iirc.

    After Compline,
    Zaxo

      Thanks for the suggestion. I have to admit whenever I see "remote X connection" I start to look for my tinfoil hat. It also seems like a bit of a heavy solution for this problem, and since the primary client OS will most likely be windows (unless some people get a clue quickly! ;), it probably wouldn't work out too well.

      Maybe I'll try that in a future project though, thanks :)