http://qs1969.pair.com?node_id=636657

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

Greetings, fellow scholastic writers of tomes!

I am writing a testing utility for a hobby hack.

Basically, I want a server which communicates with multiple clients using a line-oriented protocol. The server receives a text command from a client and sends text answers back to multiple clients.

What CPAN modules are the recommended ways these days to handle line-oriented non-blocking socket comm?

Should I look at POE or just browse the source for e.g. some smtp or chat implementations?

  • Comment on Best module to implement smtp-like protocol over sockets?

Replies are listed 'Best First'.
Re: Best module to implement smtp-like protocol over sockets?
by Your Mother (Archbishop) on Sep 03, 2007 at 03:07 UTC

    POE is great and its docs are getting better; sorry I can't point you to a specific sub-class. Also consider picking up a copy of Stein's Network Programming with Perl (I think he put all the code from the book online somewhere). You'll learn more about the guts that way. I was able to write a daemon chat server in a couple of days after picking it up.

      I checked relevant packages on Debian (my usual way to find popular non-webprogramming Perl modules not on perladvent). Danga::Socket looks good.

      Also consider picking up a copy of Stein's Network Programming with Perl (I think he put all the code from the book online somewhere).
      He sure did: "Network Programming with Perl" resources.

      And I wholeheartedly agree with your recommendation: I think this is one of the best books available on network programming, in any language.

      Thanks, I browsed that book at a friend's place once and it seems nice.

      It is just such a problem-in-a-box that there should be multiple good solutions at CPAN.

Re: Best module to implement smtp-like protocol over sockets?
by sgt (Deacon) on Sep 03, 2007 at 12:50 UTC

    line-oriented non-blocking sockets:

  • IO::SessionData (part of SOAP::Lite -- don't ask me why!)
  • IO::LineBufferedSessionData

    cheers --stephan
Re: Best module to implement smtp-like protocol over sockets?
by valdez (Monsignor) on Sep 03, 2007 at 14:37 UTC

    Ciao,

    I would start from Net::Server, in particular the samplechat.pl example; this module is a real coding pleasure ;). In case you are really interested in talking SMTP, try with Net::Server::Mail. These are two distinct distributions that play really well together.

    HTH, Valerio

Re: Best module to implement smtp-like protocol over sockets?
by former33t (Scribe) on Sep 04, 2007 at 14:09 UTC
    If your needs are simple, POE::Component::Server::TCP should do exactly what you want. Check out the following URL for a working example.

    http://poe.perl.org/?POE_Cookbook/Chat_Server

    I've had great success with POE::Component::Server::TCP in my applications.

Re: Best module to implement smtp-like protocol over sockets?
by BerntB (Deacon) on Sep 05, 2007 at 21:20 UTC

    I had to go find my password so I could vote up the answers to my question. :-)

    Thanks for the information, guys. I was quite certain there would exist neat modules, but some of those APIs are just beautiful in design and use. (I also thought POE would be complex but it was really neat.)

    (Fixed grammar, as always. Sigh.)