On 2004-01-29, Webster <we************@home.com> wrote:
Hello,
What's the best way to run a client-server interaction using some
standardized protocol such as nntp?? That is, should you run a thread that
just does a receive loop from the server so that if the server sends
anything, it will be received? Or what about if everytime you send data,
then you do a receive; so if you were *expecting* something is the only time
to call a receive??
I think it's the former because then if anything, you are getting all the
messages the server is sending and you can parse/perform actions
accordingly... but I'm not so sure :-/
Thanks!
I guess it really depends on what your trying to accomplish... But the
fact is that most standardized internet protocols - such as nntp use
your latter description...
For example, with NNTP the basic process is that the server waits on a
server listening for client connections on a known port. When a
connection is received, the server forks off a child process that gets a
new socket handle to communication with the client - then goes back
listening.
The child process then waits for commands from the client. When it
receives one, it obeys the order and returns a reply - which could be an
error... So basically, once the client sends the request it starts
trying to receive data - because it knows it is going to get some...
This is a very over simplified version of what's happening, so I hope it
makes sense...
--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
He who knows others is wise.
He who knows himself is enlightened.
-- Lao Tsu