Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom server

1 view
Skip to first unread message

Mark Richards

unread,
Dec 9, 2012, 4:15:08 PM12/9/12
to p...@perl.org
I think POE would be a good choice for what I am about to describe, but
there are a few bits I am not certain about (how to implement; whether
it's possible to implement).

I already have a working model of a server that listens on a designated
port (built in php!). It forks each connection request and handles these
independently. There may be one or 100 clients connecting at any time.
However there is the problem of zombies, and the lack of centralized
control and reporting. I want to build this in perl, and feel POE would
be a good choice.

My server waits for a connection. The client, once connected, sends a
header that contains its ID and WAN IP address. The server reads this,
and responds by either continuing some communications with the client,
or dropping the connection if it is not validated.

A valid connection provides a MODBUS ASCII session with a MODBUS network
attached to the client. So the server instance sends some MODBUS
commands and gets data in response. In the present implementation the
server keeps the connection alive for 10 minutes (this is a design
requirement - don't ask!), and then drops the connection (this is where
we get the zombies from).

What I need POE to do is the same thing, but for this I think I need a
manager of some kind that will, based on the state of the exchange,
dispatch the proper request. Each remote may require a different set of
requests, which further complicates things.

I've thrown together a simple POE version of my server. It simply
accepts the connection and reads in the first data from the client (a
header). What's missing is a way to dispatch requests dynamically and
also to wait without making the whole POE instance wait.

Hoping I have described this adequately, and that the experienced out
there might offer some suggestions as to how to approach this - and
whether POE is the right move.

Thanks!

Douglas W. Stevenson

unread,
Dec 9, 2012, 8:34:01 PM12/9/12
to mark.r...@massmicro.com, p...@perl.org
Hry Mark,


While I'm significantly less qualified than many on the POE list, I will give it a shot.


Part of what POE has taught me is to organize my code into more distinct steps 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 clones 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 via Call backs. When you need to something that blocks, you use a Run Wheel to keep your process working.


Everything starts off with a _start. In this sub, start up your SocketFactory stuff, your Run Wheels, etc. If these need to be done is specific order, 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 callbacks for each thing you need to do.


Look at delay_add to setup a delayed timer. Wait and sleep block... And when they do, so does everything else.


I built an event management system capable of handling and processing > 1 million events a minute.


HTH,


Dougie!!!
0 new messages