Re: Custom server
"Douglas W. Stevenson" <[email protected]> Sun, 9 Dec 2012 20:34:01 -0500 (EST)
| Newsgroups | gmane.comp.lang.perl.poe |
|---|---|
| Message-ID | <[email protected]> |
----------MB_8CFA48D90D5E21B_E80_72984_webmail-m089.sysops.aol.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="us-ascii" Hry Mark, While I'm significantly less qualified than many on the POE list, I will gi= ve it a shot. Part of what POE has taught me is to organize my code into more distinct st= eps where I can stack them up and execute them asynchronously. Part of the thing with Fork is that when you look under the covers, it clon= es the process. So, every time you fork, you create a new instance. With POE, you organize the things you need to do in subroutines accessed vi= a Call backs. When you need to something that blocks, you use a Run Wheel = to keep your process working.=20 Everything starts off with a _start. In this sub, start up your SocketFact= ory stuff, your Run Wheels, etc. If these need to be done is specific ord= er, use a yield yo callback to the stack a separate subroutine to start the= other things. As things start running and you accept connections, each accept sets up cal= lbacks for each thing you need to do. Look at delay_add to setup a delayed timer. Wait and sleep block... And whe= n they do, so does everything else. I built an event management system capable of handling and processing > 1 m= illion events a minute. HTH, Dougie!!! -----Original Message----- From: Mark Richards <[email protected]> To: poe <[email protected]> Sent: Sun, Dec 9, 2012 3:15 pm Subject: Custom server I think POE would be a good choice for what I am about to describe, but=20 there are a few bits I am not certain about (how to implement; whether=20 it's possible to implement). I already have a working model of a server that listens on a designated=20 port (built in php!). It forks each connection request and handles these=20 independently. There may be one or 100 clients connecting at any time. =20 However there is the problem of zombies, and the lack of centralized=20 control and reporting. I want to build this in perl, and feel POE would=20 be a good choice. My server waits for a connection. The client, once connected, sends a=20 header that contains its ID and WAN IP address. The server reads this,=20 and responds by either continuing some communications with the client,=20 or dropping the connection if it is not validated. A valid connection provides a MODBUS ASCII session with a MODBUS network=20 attached to the client. So the server instance sends some MODBUS=20 commands and gets data in response. In the present implementation the=20 server keeps the connection alive for 10 minutes (this is a design=20 requirement - don't ask!), and then drops the connection (this is where=20 we get the zombies from). What I need POE to do is the same thing, but for this I think I need a=20 manager of some kind that will, based on the state of the exchange,=20 dispatch the proper request. Each remote may require a different set of=20 requests, which further complicates things. I've thrown together a simple POE version of my server. It simply=20 accepts the connection and reads in the first data from the client (a=20 header). What's missing is a way to dispatch requests dynamically and=20 also to wait without making the whole POE instance wait. Hoping I have described this adequately, and that the experienced out=20 there might offer some suggestions as to how to approach this - and=20 whether POE is the right move. Thanks! =20 ----------MB_8CFA48D90D5E21B_E80_72984_webmail-m089.sysops.aol.com--