On Fri, Aug 29, 2014 at 1:18 AM, Sam <p...@net153.net> wrote:

> Are you saying the normal 'unix' way won't work? (ie. listen on socket, fork
> on an accepted connection, do the work, close)

Not at all.  My problem is not related to creating, accepting, or
forking at all.

The block / waiting occurs whilst the socket is already connected.  I
think a better way to describe this from terms I've seen whilst
googling... I need to be able to read & write simultaneously on the
socket after the client connected.

Again, as per my example given, that is one single client socket
connected to the server.  The asynchronous part comes in to the effect
that the client must be able to CONTINUOUSLY (non blocking) supply
commands to the server, whilst the server MAY take a large time before
responding to those commands.  Now, every single (almost) perl
application I've looked at, does this to some form of degree in terms
of reading/writing on sockets...

while (1) {
  # read $_ from socket
  # do stuff with $_
  # respond to client with some form of print
}

In that example, whilst you are doing stuff with $_ (the workload,
sleep($randomtime) in my example, the client is blocked and the client
cannot write to the socket (or technically it can, but the server
can't process it rather).  I am thus referring to the communication
stream, needing to be asynchronous.

I don't even know how to accurately present this in text, but I'm
basically after something to the tune of the below.  And the *real*
crux of the matter is going to be that the writing will indeed
sometimes happen at the *same time* as what the reading will happen.
Or at least, it needs to.

while (1) {
  # read $_ from the socket and pass it to some non blocking sub / event handler
}

sub processit {
  # do stuff with $_
  # respond to the client with some form of print
}

SMPP is a protocol which can be seen as a very good example.  Whilst
it CAN work synchronously (receive data, process it, respond), it
operates immensely better when it's written as a asynchronous
application.  THe same with certain aspects of NNTP for example (RFC
4644), and I'm sure that there is allot of other examples I can give
where asynchronous communication is absolutely vital.

I'm most certainly also not saying that it isn't possible with Perl
either.  All that I am saying is that, to date, I have not been able
to find one single example, recipe, or cookbook entry on HOW to do
this.  Not wanting to step on any toes, but I almost get the feeling
that the examples of code being given is rather outdated.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to