22.12.2013 Views

Roku Object Reference - imaginArt

Roku Object Reference - imaginArt

Roku Object Reference - imaginArt

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

oDatagramSender, roDatagramReceiver ()<br />

The roDatagramSender and roDatagramReceiver classes allow for simple sending and receiving<br />

of unicast and broadcast UDP packets.<br />

roDatagramSender allows UDP packets to be sent to a specified destination. It implements<br />

ifDatagramSender.<br />

roDatagramSender is created with no parameters:<br />

• Create<strong>Object</strong>("roDatagramSender ")<br />

The ifDatagramSender interface provides:<br />

• SetDestination(destination_address As String, destination_port As<br />

Integer) As Boolean<br />

o Specify the destination IP address in dotted quad form along with the destination port. Returns<br />

true on success.<br />

• Send(packet As String) As Integer<br />

o Send the specified data packet as a datagram. Returns zero on success or a negative error<br />

number on failure.<br />

roDatagramReceiver causes events to be sent to a message port when UDP packets are received on<br />

the specified port. It implements ifIdentity and ifSetMessagePort.<br />

roDatagramReceiver is created with a single parameter:<br />

• Create<strong>Object</strong>("roDatagramReceiver ", port As Integer)<br />

o Specify the port on which to receive UDP packets.<br />

Examples:<br />

‘ This script broadcasts a single UDP packet containing “HELLO” to<br />

‘ anyone on the network listening on port 21075.<br />

sender = Create<strong>Object</strong>(“roDatagramSender”)<br />

sender.SetDestination(“255.255.255.255”, 21075)<br />

sender.Send(“Hello”)<br />

‘ This script listens for UDP packets on port 21075<br />

receiver = Create<strong>Object</strong>(“roDatagramReceiver”, 21075)<br />

mp = Create<strong>Object</strong>(“roMessagePort”)<br />

receiver.SetPort(mp)<br />

while true<br />

event = mp.WaitMessage(0)<br />

if type(event) = “roDatagramEvent” then<br />

print “Datagram: “; event<br />

endif<br />

end while<br />

59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!