Socket Comm Followup - A couple of questions

Ken Ray kray at sonsothunder.com
Sat Apr 16 01:51:44 EDT 2005


On 4/16/05 12:36 AM, "Mark Wieder" <mwieder at ahsoftware.net> 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.

Thanks... I implemented a length byte approach where I send the length of
the data, a CR, then the actual data, and read the length first and then
read the length in bytes. Works really nicely. :-)

> 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.

Thanks for the clarifications... I really appreciate it.

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list