Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

creating a state machine

by particle (Vicar)
on Mar 11, 2003 at 22:43 UTC ( [id://242182]=perlquestion: print w/replies, xml ) Need Help??

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

i'm trying to put together a proxy between the server end of a client/server application, and a code repository. the repository is on win32, the server on solaris. i thought i'd write a sockets-based app that would handle communications with a protocol somewhat like SMTP. you'll find some of the design details below.

the design is basically complete, although i haven't included all the info below. now it's time for the implementation... which is where i'm stuck. i have a functioning sockets client/server pair (that's the easy part.) i don't have gobs of time to get this implemented -- i'd like to have it finished this week. i know there are modules like POE and DFA, but i'm not at all familiar with them. is there some sample code out there i can model this after, or could someone please provide some? i just need a kickstart and i'm sure i can handle the rest. thanks in advance.

now, for the details. there are six basic operations the server can perform:

  • HELLO <clientname> -- begins a connection, allows server to perform client validation.
  • GET <username> <filename> -- gets a revision from the repository
  • UNL <username> <filename> -- unlocks a revision in the repository
  • PUT <username> <filename> -- puts a revision in the repository
  • EXIT -- ends a connection
  • DATA -- specifies data will be sent (either from server to repository, or repository to server, depending on whether a GET or PUT command is sent from the server)
my state diagram looks like this:

init | V HELLO / | \ / | \ / | \ GET UNL PUT | | | V V V DATA-->EXIT<--DATA | V end

five of the commands (HELLO, GET, UNL, PUT, EXIT) have a similar state diagrams. here, B is 'begin', W is 'wait', S is 'success', and F is 'failure'. success returns 'OK', failure returns a detailed error message.

+---+ cmd +---+ +---+ | B |------>| W |---->| S | +---+ +---+ +---+ | | +---+ ------>| F | +---+

the DATA command is a bit different, as shown in it's diagram below.

+---+ DATA +---+ | B |------->| W | +---+ +---+ | | ------------ ----- | | +---+ | --------->| S | | | | +---+ V | | +---+ data +---+ -->+---+ | |------->| W | | F | +---+ +---+------->+---+

did i mention it's a bit like SMTP? here the DATA command is sent, followed by multiple lines of data, and a terminator. a success or failure message is generated.

please let me know if you need any more detail, or clarification.

~Particle *accelerates*

Replies are listed 'Best First'.
•Re: creating a state machine
by merlyn (Sage) on Mar 11, 2003 at 22:52 UTC
    Do you really need to maintain a connection between steps? If you can get away without that, consider HTTP and maybe SOAP over HTTP instead. It's trivial to build HTTP servers and clients with Perl (even cross platform). And because the protocol is well understood and debugged, life is so much easier.

    HTTP also offers the niftiness of large data in both directions, 8-bit clean data, and meta-data (headers in request and response), and well-defined authentication methods. Plus, if you're smart, you can perform some of the operations from an ordinary browser as well as custom programs.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      ...and soap it is. thanks for getting me thinking in another direction.

      ~Particle *accelerates*

Re: creating a state machine
by IlyaM (Parson) on Mar 11, 2003 at 23:31 UTC
Re: creating a state machine
by kschwab (Vicar) on Mar 12, 2003 at 03:03 UTC
    You might check out Net::Cmd. It handles most of the details of an "SMTP like" protocol.

    Other modules, like Net::SMTP, Net::SNPP, and Net::FTP derive from it.

    Those are all, of course, client oriented modules, so none it really helps with your state-machine, but it would help with the line-oriented protocol.

    If POE isn't your cup of tea, you might like Net::Server. Similarly named, but unrelated is NetServer::SMTP which shows how to use Net::Cmd within a state-machine type server.

Re: creating a state machine
by tall_man (Parson) on Mar 12, 2003 at 03:12 UTC
    I've had good results using Frontier::RPC2 clients and servers, an XML RPC implementation for perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://242182]
Approved by Mr. Muskrat
Front-paged by demerphq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found