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

As most of you know (well, maybe), that I have been working on some OO modules for use in a program set (1 server and 1 client) at my job (found here). In the beginning, I decided that this would be a pure Perl project (well, some C for the over-the-wire transport via Socket.pm). So far, so good.

Thanks to advise from tilly and others (too many to list), I've been able to abstract most of the elements of my code into a fairly decent class of modules. Student.pm is a base class with constructor and delegate and accessor methods. Student/Server.pm is a module that is for server use (mainly) and has methods for server-side tasks. Student/Client.pm, obviously, is a module used client-side. While there are some definite improvements to be made to the abstraction used in these modules, I think they're almost decent enough to run in production. I will post the code up at my home node (if I can get away with it) for these three modules.

The last things I need to clear up before I can even test the code based on these modules (rpc_server.pl and rpc_client.pl... source for these will be on my scratchpad soon) in production are:

1.) The RPC module I used (alpha module discussed in Advanced Perl Programming) is made with running remote subs (in the form of pkg::sub), not with running OO commands. This causes quite a problem with my OO code (obviously). There are two ways to solve this: a.) use another module (which is somewhat tricky in the Win32 environment, where IPC is kinda shaky) or b.) edit/rewrite the module to allow for OO.

To do the second option would require a lot of time (diving through the code and such). I'm not as familiar with socket programming in perl as most (hopefully, I can get my hands on the Network Programming with Perl book that everyone recommends in the near future), so some of the code that Sriram used in the RPC module is kinda weird to me. If anyone knows of any resources that have information on socket programming in Perl (free, preferably...), please let me know via PM, email, whatever...

2.) Student, Student/Client, and Student/Server are meant to separate functions that are required by the server and client ends. Basically, all of the major client requests are not in the client module at all. They are supposed to be delegated to the server via RPC. I wrote a small AUTOLOAD routine that will copy the student objects, bless them in the server class, and call the method from the server class. This approach works (somewhat), but it requires that the server and client classes be used by the client program (which kind of defeats the idea of abstracting the two sets of code into modules). Would anyone have some suggestions as how to set this delegation up better?

Any suggestions, comments, etc. would be appreciated.

Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com
  • Comment on Rather complicated OO (and RPC) question...

Replies are listed 'Best First'.
Re (tilly) 1: Rather complicated OO (and RPC) question...
by tilly (Archbishop) on Mar 03, 2002 at 03:47 UTC
    A hint on getting better luck with answers. People tend to be more likely to answer focussed questions. Broad, general questions are intrinsically hard to aswer because you don't know where to start or what level to pitch it at.

    If you want to do RPC invocations in Perl then I would suggest using an Apache/CGI model because that network code is well understood and debugged. Failing that I would suggest starting with POE for the server. (Of course if you are nearly done, a rewrite to either model may not be worthwhile.)

    Beyond that, without a specific socket or RPC question the best that anyone can say is that Lincoln Stein has this great book, there are examples in the Cookbook, and some examples in the documention. If there is something you can put your finger on that you don't understand, it might be worthwhile asking that.

    As for a poor factoring between clients and servers, my gut feeling says that it makes sense for clients and servers to share code for part of the communication. I would therefore not be bothered that your clients use that even though you nominally thought that those routines belong in your server class.

    Hopefully this is helpful. It isn't very concrete I know, but it is very difficult for me to find satisfactory answers to general questions.

      I should point out that this server/client setup is not to use any web servers. The reason being that it requires extra resources on the server (to make sure the web server doesn't bog down the machine). Basically, the only thing I really need to do is setup a socket server, sit it on a port, and wait for connections (using an infinite loop and IO::Select). When a socket comes alive and is ready for reading, then I can capture the data, wrap it in an eval(), and write the results back to the socket. This method seems to me like a better way to go, since it won't be as resource intensive (I can easily have it close after an amount of time and re-run it at a scheduled time). The only thing I haven't figured out is how to remember which socket is being read and which socket will be written to after the eval is completed. I think a little more diving into socket programming will help me to overcome that.

      The POE set of modules also seems like a good idea. The only thing I worry about is implementation of my code over the wire using that module (I was reading the docs for the base POE class, and it didn't say anything about OO... I might have to read further into it). In most cases, WWW stuff would be a good idea if this was over the entire net. Since this is a LAN based project, I think a webserver with all of the XML and stuff is quite an overkill (not to mention that WWW stuff is pretty foreign to me in the first place). Simple RPC is all I need.

      Theodore Charles III
      Network Administrator
      Los Angeles Senior High
      4650 W. Olympic Blvd.
      Los Angeles, CA 90019
      323-937-3210 ext. 224
      email->secon_kun@hotmail.com
        What kind of machines are you talking about?

        You mentioned Windows. The GUI on Windows continually takes up several times the resources of a webserver. Any Windows machine with enough resources to run Office can function perfectly well as a webserver. Or to put it another way, a P100 with 32 MB of RAM is overkill for running a low-volume webserver, as long as you are using an OS that is not resource heavy. (Erm, you mentioned Windows? Nevermind.)

        I highly doubt that server resources will be a constraint preventing your running a webserver.

        Now your not knowing WWW is a good argument against. But on the other hand the amount you need to learn to write a CGI is less than the amount you need to learn to write a custom client-server application...

Re: Rather complicated OO (and RPC) question...
by perrin (Chancellor) on Mar 02, 2002 at 17:16 UTC
    There are several RPC modules on CPAN that look pretty solid. Why don't you try one of those? Top candidates include RPC::XML, PlRPC, and the various SOAP modules.