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

Hi all.

I am in the process of writing a perl based server for a professor of mine ( non-homework ) and I need a little help with some of the design aspects. Please see below for details:

Homework server:



Here is the code so far:

# Perl client #!/usr/bin/perl -w use strict; use IO::Socket::INET; local $| = 1; my $host = '127.0.0.1'; my $port = 8500; my $client = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM, ) or die "Couldn't create client : $!\n";


#Perl server #!/usr/bin/perl -w use strict; use IO::Socket::INET; local $| = 1; my $response; my $port = 8500; my $client; my $server = new IO::Socket::INET( LocalPort => $port, Type => SOCK_STREAM, Listen => 5, Proto => 'tcp', Reuse => 1, ) or die "Couldn't construct server on port: $port : $!\n"; $client = $server->accept(); $response = <$client>; chomp $response;

I don't have access to a database ( at work ) yet so I was considering hard coding the id / pw combinations as constants in the server.pl file. I could fortify this application if I were to write it as a CGI program ( setting maximum uploads, etc. ) in order to guard against DOS attacks.

Any help would be greatly appreciated,
I'll post the completed code ( both client and server ) when it has been completed.

Thanks,
-Katie.

Replies are listed 'Best First'.
Re: Writing a perl based 'Homework' Server.
by TGI (Parson) on Apr 18, 2003 at 06:50 UTC

    I thought Perlmonks was already the Perl homework server!

    If ftp won't cut it, perhaps you should consider a web based system. You can use either a CGI or a mod_perl solution (HTML::Mason is a favorite tool of mine). Then you don't have to write a client (any browser will do) and you don't have to write a complete server (Apache doesn't cost much). You'll still need to put together application logic and build an interface, but you'd've had to do that anyway.

    If you really need to use a PERL client, then write one using LWP ;)


    TGI says moo

Re: Writing a perl based 'Homework' Server.
by vbrtrmn (Pilgrim) on Apr 18, 2003 at 12:13 UTC
      I agree with using "htaccess and cgi". That's the easiest way. When the student uploads the file, have the cgi script scan it for a student number and file it in the appropriate directory. htaccess is easy to get working, and there are numerous ways to upload files to a cgi script using lwp. Just talk your professor into setting up a "password protected homepage" for each class. Just make sure that the "storage directory for uploaded homework" isn't accesible by a browser, or you could get rampant copying. :-)
Re: Writing a perl based 'Homework' Server.
by gmpassos (Priest) on Apr 18, 2003 at 07:59 UTC
    Well, what you need is to learn Sockets with Perl. ;-P

    If you want to enable the access of multi users in the same time to the server, take a look in this node: Re: spawning Perl scripts (Win32/Linux sample) (to run concorrent codes without threads). The use of fork is only recomended on Linux, on Win32 use threads (Perl-5.8.0).

    But note that you need to know if who is connected to the server are sending right the data, or only opening the door, to avoid a basic DOS attack. To do that you can use IO::Select, but will read byte by byte!

    Other thing is to limit the access to the srv for only some IPs:

    my $server = IO::Socket::INET->new( Listen => 5, LocalAddr => '192.168.0.0', LocalPort => 5050, Proto => 'tcp' ) ;

    About the users id and pass, you can (should) use a database. Just take a look in DBI. For a very simple database, with flat files, use DBD::CSV, or DBD::SQLite. The both don't need a main server, the module work as the srv.

    And CPAN is your friend: http://search.cpan.org

    Graciliano M. P.
    "The creativity is the expression of the liberty".

      Hi.

      Thanks for the advice. I am 'limited' to perl 5.6 ( school ) but I did manage to expand on my code base:

      # Perl server #!/usr/bin/perl -w use strict; use IO::Socket::INET; local $| = 1; my $ID; my $PW; my $port = 8500; my $client; my $server = new IO::Socket::INET( LocalPort => $port, Type => SOCK_STREAM, Listen => 5, Proto => 'tcp', Reuse => 1, ) or die "Couldn't construct server on port: $port : $!\n"; $client = $server->accept(); print $client "ID:"; $ID = <$client>; print "I received $ID\n";


      #Perl client. #!/usr/bin/perl -w use strict; use IO::Socket::INET; local $| = 1; my $host = '127.0.0.1'; my $port = 8500; my $ID; my $PW; my $client = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM, ) or die "Couldn't create client : $!\n"; my $data = <$client>; print $data; chomp( $ID = <$client> ); print $client $ID;


      The primary problem is I can pass the prompt to the client ( e.g. ID? ), but I don't know how to obtain the input then return that to the server. I tried <STDIN> but the program simply hung. If I can prompt for three scalars ( ID, PW, and assignment_to_submit ) and return each piece of input to the server, I don't forsee too much difficulty in completing the remainder of the project.

      Thanks,
      -Katie.
        Well, STDIN should work!
        print "Type some: " ; my $in = <STDIN> ; chop($in) ; print "In: $in\n" ;
        But in what OS the client work? You can put a GUI for the app, like wxPerl or TK.

        Graciliano M. P.
        "The creativity is the expression of the liberty".

Re: Writing a perl based 'Homework' Server.
by Zaxo (Archbishop) on Apr 18, 2003 at 06:20 UTC

    Would ftp with AUTH do what you want?

    After Compline,
    Zaxo

      Hi Zaxo.

      Yes it would but I have to present a software project at school next month and since several of those in attendance use perl...

      There is something deeply satisfying about writing your own tools and giving them away to students and colleagues. I am a very generous person so I need an excuse to exhibit my altruistic nature.

      -Katie.
(jeffa) Re: Writing a perl based 'Homework' Server.
by jeffa (Bishop) on Apr 18, 2003 at 16:26 UTC
    Hi Katie,
    Random thoughts ahead ... At our university, the CompSci department has a Linux box (called torvalds) that professors can assign accounts for. One of my professors wrote a very simple program on this computer that accepts students assignments. In order for a student to turn in an assignment (which is contained in a tar ball), they have to log in to torvalds and run this script (locate in /usr/bin/ or such). The script accepts the name of the tar ball, and copies it to a protected directory with a new name (probably a combo of the student's login name and assignment number). No database is used. A student can submit their assignment multiple times, each new submit simply copies over the old one. The script also has a deadline set so that students cannot turn in late assignments. The script has to run as root, so precautions are needed, but other than that - it is very simple and very effective.

    I am not sure if you can use any of these ideas. But i thought i would share none the less. I wish i could simply post the code that my professor wrote ... but he won't let me. ;) Besides, i don't think it's written in Perl anyway.

    Best of luck!

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Writing a perl based 'Homework' Server.
by hardburn (Abbot) on Apr 18, 2003 at 13:49 UTC

    If you can install modules, try DBD::SQLite, which provides a full RDBMS embedded in the module itself.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: Writing a perl based 'Homework' Server.
by thealienz1 (Pilgrim) on Apr 18, 2003 at 17:39 UTC

    The best thing that I can think of that has been useful to me, and made everything simple... is jellybean.

    There are things that may come, and things that may leave, but all in all, we are still looking for the magical mushroom goats.

Re: Writing a perl based 'Homework' Server.
by oylee (Pilgrim) on Apr 21, 2003 at 03:52 UTC
    You might also want to check out
    Vincent, a system that one of our own created a while back to handle homework submissions for the CS department... It appears that you might be looking for a quick/easy solution, so this might be a bit of overkill...