Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The following is a description of a protocol I designed for an job candidate examination:
   Receives lines from a client:
      iam <id>
      need-done <args>
   In response to a need-done, sends to a client that has given
   an "iam" message:
      dothis <args>
   Server ignores any other lines
It's basically a trivial job dispatch protocol where clients register to do work with a central server and are also able to request jobs. Designwise, it's pretty much all that the described chat server would do.

The exam question asked them to describe the protocol given the following code and then identify at least three security holes (with proposed attacks) in the protocol as well as explain how you'd fix the security problems. Which is why it was written so badly. Sorry...

use Socket; socket S, PF_INET, SOCK_STREAM, getprotobyname('tcp') or die "$!"; setsockopt S, &SOL_SOCKET, &SO_REUSEADDR, 1 or die "$!"; bind S, sockaddr_in( 23456, INADDR_ANY ) or die "$!"; listen S, 5 or die "$!"; $SIG{__DIE__} = sub { close S; }; $rin = ""; vec( $rin, fileno(S), 1 ) = 1; while( 1 ) { next unless select( $rout = $rin, undef, undef, undef ) > 0; if( vec( $rout, fileno(S), 1 ) ) { local *H; $p = accept( H, S ); select( (select(H), $| = 1)[0]); push @known, *H; vec( $rin, fileno(H), 1 ) = 1; } foreach my $fd (@known) { if( vec( $rout, fileno($fd), 1 ) ) { $s = readline $fd; push @able, $fd if $s =~ /^iam\s+(.+)\s*$/io; if( @able and $s =~ /^need-done\s+(.+)\s*$/io ) { print { $able[(unpack "%32C*",$1) % @able] } "dothis ", $1 +, "\n"; } } } }
For some reason, only one candidate even attempted the question.

That aside, it's certainly possible to write a chat server in perl. It's not threaded, but I don't see why you'd really want a threaded server when so much state has to be shared between all the processes and the overhead of serving requests is so low.

c.


In reply to Re: Chat server impossible with Perl? by beauregard
in thread Chat server impossible with Perl? by bronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-16 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found