UDP Broadcast (was Re: Program Linking)

Ian Summerfield iansummerfield at btconnect.com
Sun Mar 17 18:26:01 EST 2002


On 13/3/02 9:59 pm, "Dar Scott" <dsc at swcp.com> scribed:

> I use "accept datagram socket".  There might be a better way.  I
> described how I do this in recent mail to improve-revolution with
> the subject ""accept datagram" on W2K is not that on OS X".
> 
> Essentially, I open with "accept" specifying the message for
> handling datagrams.  Those messages are sent with the sender's IP
> address and with the datagram content.  NB: Close the socket with
> the port only; if you look at openSocket, you will see the socket
> listed in that form.
> 
> The problem (or feature) with OS X is that an additional message is
> sent upon "accept" and only one valid datagram can be received.
> The "datagram" for the extra message empty, so if you make sure no
> valid datagram is empty, you can ignore it based on that for both
> platforms.  If you need to receive more than one datagram, you have
> some work to do.  Otherwise just close it at the end of the second
> message handling.  You can reopen it to receive more.

I didn't know any of what you said.  I'm working on OS X, and this evening
just finished a little project to monitor an APC UPS.  I used "accept
datagram" but then found the "have some work to do" bit you refer to was
only a case of calling "read from socket nnnn with message xxxxxx" at the
end of my message handler.   It works fine.   Is this the proper approach?

on mouseup
  accept datagram connections on port 3052 with message "gotGram"
end mouseup

on gotGram fromwho,what
  if what is not empty then
    -- do whatever I want with the data
  end if
  read from socket 3052 with message "gotGram"
end gotGram





More information about the use-livecode mailing list