Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Rek
Visitor

Documentation Error

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!
0 Kudos
1 REPLY 1
RokuMarkn
Visitor

Re: Documentation Error

Thanks, it's fixed now.

--Mark
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.