Running a client-server interaction program

  • Thread starter Thread starter Webster
  • Start date Start date
W

Webster

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!
 
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
 
Cool thanks!

But there was a nntp server I logged into once that said it will log me out
after 10 seconds of being idle... So how could you know when the server is
going to send the disconnect command?? (unless you time it your self on your
end)
 
Cool thanks!

But there was a nntp server I logged into once that said it will log me out
after 10 seconds of being idle... So how could you know when the server is
going to send the disconnect command?? (unless you time it your self on your
end)

It probably wouldn't send a disconnect command... More than likely it
would just close the socket - expecting you to trap the exception or
detect a 0 return value from recv to know that the socket was closed...
 
It probably wouldn't send a disconnect command... More than likely it
would just close the socket - expecting you to trap the exception or
detect a 0 return value from recv to know that the socket was closed...

Oh I see... how rude!! ;-P
 
Back
Top