Hey all, I just noticed that there is an error with the code example on this page:
http://sdkdocs.roku.com/display/sdkdoc/roDataGramSocket
' UDP 2-way peer-to-peer asynchronous comm on port 54321
' periodically sends out a message to a specific address and port
' prints any message it receives
Function UDPPeer()
msgPort = createobject("roMessagePort")
udp = createobject("roDatagramSocket")
udp.setMessagePort(msgPort) 'notifications for udp come to msgPort
addr = createobject("roSocketAddress")
addr.setPort(54321)
udp.setAddress(addr) ' bind to all host addresses on port 54321
addr.SetHostName("10.1.1.1")
udp.setSendToAddress(addr) ' peer IP and port
udp.notifyReadable(true)
timeout = 1 * 10 * 1000 ' ten seconds in milliseconds
uniqueDev = createobject("roDeviceInfo").GetDeviceUniqueId()
message = "Datagram from " + uniqueDev
udp.sendStr(message)
continue = udp.eOK()
While continue
event = wait(msgPort,timeout)
If type(event)="roSocketEvent"
If event.getSocketID()=udp.getID()
If udp.isReadable()
message = udp.receiveStr(512) ' max 512 characters
print "Received message: '"; message; "'"
End If
End If
Else If event=invalid
print "Timeout"
udp.sendStr(message) ' periodic send
End If
End While
udp.close() ' would happen automatically as udp goes out of scope
End Function
In the line:
event = wait(msgPort,timeout)
The args have been reversed. It should be:
event = wait(timeout,msgPort)
Cheers!