On Mon, 27 Aug 2001 Rodney Tamblyn <[EMAIL PROTECTED]> wrote:

> Some socket questions:
>  When using sockets to read and write I have been using the
> following approach: write the length of the packet on a line
> followed by the data, at receiving end read for one line, then read
> for the supplied number of characters.  What approaches do others
> use?  You can also read without specifying a "for" condition, a
> specified handler will be called when data arrives.  Are there any
> advantages/disadvantages of one approach over the other?

The simpler "read from socket <x> with message <y>" is much more
efficient, and is the *only* reasonable way to use sockets that will
be exchanging large amounts of data or when communicating with a large
number of other hosts.  I find it more convenient even for
smaller-scale development because as long as the host on the other end
always writes a complete message (and as long as it's less than 4K in
length), you don't have to worry about this length/data problem: all
the data they wrote in a single "write" command will come in with the
message.

> In general, if you have two stacks that are going to have an ongoing
> series of communications going backwards and forwards, is it better
> to leave the socket open, or always close the socket after each
> communication.  I've assumed the latter.

Definitely: setup time for a TCP socket is pretty large, so you want
to leave a socket open as long as there's any chance that you'll need
to read or write to it later (this is the issue behind the
"Keep-Alive" extension to the HTTP that was the big feature added for
version 1.1 of that protocol).  Note that "socketTimeout" messages
will be sent periodically if the socket is inactive for the amount of
time specified in the socketTimeoutInterval property.  You can either
just ignore them or use them as a cue to close the socket and notify
the user that something has gone wrong.

> Presumably there is a limit on the number of sockets MC can have open?

Yes, but it depends on the OS and even on how a particular system is
set up.  A generally-safe lower bound is 20.

> When MC has an open socket, does it periodically attempt to verify
> whether the remote party is still present?

No, TCP does that automatically.  When the connection is dropped at
the other end (or someplace in the middle ;-) MetaCard will get an
event that will result in a "socketClosed" or "socketError" message
being sent, depending on exactly what happened.

> Any other comments or tips from people who are experienced using
> sockets in Metacard would be appreciated.

The libURL script is getting to be a little large to use as a source
of examples, but it wouldn't hurt to browse through it.  I also have a
little telnet client that I'd be willing to send to anyone who needs
examples of how to communicate with a telnet server or to get a
general idea of how two hosts can communicate.
  Regards,
    Scott

> Rodney
> -- 
> --
> Rodney Tamblyn
> Educational Media group
> Higher Education Development Centre, 75 Union Place
> University of Otago, PO Box 56, Dunedin, New Zealand
> ph +64 3 479 7580 Fax +64 3 479 8362
> http://hedc.otago.ac.nz ~ http://rodney.weblogs.com

********************************************************
Scott Raney  [EMAIL PROTECTED]  http://www.metacard.com
MetaCard: You know, there's an easier way to do that...



Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to