>From: Rodney Tamblyn <[EMAIL PROTECTED]>
>Subject: sockets
>Date: Mon, 27 Aug 2001 17:08:59 +1200
>MIME-Version: 1.0
>Content-Type: text/plain; charset="us-ascii"
>
>I have been having fun working with sockets in Metacard, and in 
>general everything seems to work fine.
>
>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?

read from socket s with message "newData"

is probably the best way...it threads the socket reading, so your 
program doesn't come to a halt.

You just need to handle the newData message (or whatever you want to 
call it) which has the data and the socket.  You should wrap your 
communications in something (i use <reply></reply> so you know when 
you have all of your data (i.e. if its a bunch of data, you might get 
a couple of messages with only part of the info).

As far as leaving them open, I tried leaving them open for short 
bursts...something like
        Computer 1      Computer 2
        Request
                        Process Request
                        Send OK or more data
        if OK, close socket
        if data, process and send back ok or data

and continue until one says "OK".

Unless you are doing something high-speed like online gaming, I think 
that its smarter to close sockets...but I could be wrong at that..

Hope this helps!

-ml



>
>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. 
>
>Presumably there is a limit on the number of sockets MC can have open?
>
>When MC has an open socket, does it periodically attempt to verify 
>whether the remote party is still present?
>
>Any other comments or tips from people who are experienced using 
>sockets in Metacard would be appreciated.
>
>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
>
>

-- 
Mark J. Luetzelschwab   [EMAIL PROTECTED]          
Graduate Research Assistant     (v) (512) 232 6034
Instructional Technology        (f) (512) 232 2322
Reading and Language Arts:      http://www.texasreading.org

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