|
Thank very much for you good answer Bill, i'm on
it.
Do you know where i can view an example
code showing all this? (or do anyone else reading this message
know?)
Thanks a lot for your time.
Paco.
----- Original Message -----
Sent: Wednesday, September 13, 2006 8:15
PM
Subject: Re: Good IO::Socket::INET
examples
Paco Zarabozo A. wrote:
> Hello All, >
> I'm trying to write a server using IO::Socket::INET, which is
supposed > to read different commands from a human client connected
through telnet. > Depending on the received commands, the server should
process whatever > it received to give an answer to the client (pretty
simple, huh?). > > The thing is that i just don't
understand how to use IO::Socket::INET to > read the commands sent by
the client (i'm getting stucked while reading > the client), and i can't
find a good example on the web of how to do > that. Also, the
documentation for IO::Socket::INET is not helping me too >
much. > > Can anyone please give me a few urls where good
examples of > server-client conversations are explained or provide me
with a good > example of a server reading what the client says and
answering according > to that? Also, i want to understand how this
should be written to accept > several clients in the same port at the
same time (like any server > normally works).
All you need to do
is open a listen socket, add it to a select mask (IO::Select) and enter a
processing loop with a can_read request to IO::Select. If a socket is
ready, determine if it is the listen socket and if so, do an accept and add
it to your read mask. Else it's an already connected socket, so read
the socket.
It's probably best to queue outgoing data to a queue and
periodically try to output the write data - that way you aren't
interrupting your processing of incoming data too much and it's a nice
simple main loop.
One rule is to never attempt a read unless you have a
good response from can_read and only do 1 read before checking again with
can_read or you could lock yourself up. An alternative would be to
use a non-blocking read.
A reasonable solution would be to Q all
incoming and outgoing data and then work the Q's in your main loop.
Obviously you would need to try to fill your Q's in the main loop also by
calling the read and write Q filling/emptying routines. The hardest
part for TCP is determining where records start and end - in your case you
would probably go line by
line.
_______________________________________________ ActivePerl
mailing list [email protected] To
unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs