Socket Comm Followup - A couple of questions

Mark Wieder mwieder at ahsoftware.net
Sat Apr 16 01:36:32 EDT 2005


Ken-

I'm just getting adjusted to getting back to civilization after a
couple of weeks and catching up on a *lot* of email, so I may have
missed some points in this thread, but...

Friday, April 15, 2005, 8:27:00 PM, you wrote:

KR> 1) I noticed that in Alex's examples, after the "listener" gets the message
KR> fired off after the "accept" has been triggered, the "read from socket"
KR> command says "read from socket lSock until CR"... any reason to read only a
KR> line of data at a time? If I am sending over lots of data, what's the
KR> good/bad thing about reading it in all at once?

Well, you have to have some way of knowing when the message has ended.
TCP is a stream-oriented protocol. The message you send may be broken
up into several packets or may not. Your message may end in the middle
of a packet and the next one may start in the same buffer. One way for
the receiver to tell that you've reached the end of a message sent
from the transmitter is to use a delimiter char. For text streams this
is normally a CR character. Otherwise when you're sending over lots of
data how do you know you've reached the end? The receiver will time
out waiting for another char.

KR> 3) When should one use UDP vs TCP? What are the ads/disads of each?

Normally you would stay away from UDP unless you really need it. UDP
is message-oriented rather than stream-oriented, which is nice, but it
lacks the guaranteed deliverability and packet sequencing of TCP. It's
somewhat faster since you don't have the header information that TCP
uses to determine sequencing. It's used a lot for control sequences
where the order of packets doesn't matter and the packets are assumed
to have reached their destinations.

-- 
-Mark Wieder
 mwieder at ahsoftware.net



More information about the use-livecode mailing list