Android Question B4A Roku Control

mhartwig

Member
Licensed User
Longtime User
I have been ripping my hair out trying to figure this out. I can get a listing of the channels, I can scan for roku's via SSDP per the doc. But I cannot seem to launch or send keypresses. I am using UDPSocket to send a post. I have double checked the IP and port are correct per the documentation.

I get no response.

The roku control documentation can be found here:
http://sdkdocs.roku.com/display/sdkdoc/External+Control+Guide

B4X:
Public Sub Press(Action As String)
    Dim uc As UDPSocket
    udpClient = uc

    udpClient.Initialize("PRESS", port, 8000)
   
    Dim packet As UDPPacket
   
    Log("Sending Action: " & Action)
   
    Dim toSend As String : toSend = "POST /keypress/[KEY] HTTP/1.1\r\n\r\n".Replace("[KEY]", Action).Replace("\r\n", CRLF)
   
    Log(toSend)
   
    'Do a simple write
    Dim sendBytes() As Byte : sendBytes = toSend.GetBytes("UTF8")
   
    packet.Initialize(sendBytes, host, port)

    udpClient.Send(packet)
End Sub

Sub PRESS_PacketArrived(Packet As UDPPacket)
    Dim msg As String
    msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")

    Log(msg)
End Sub
 

mhartwig

Member
Licensed User
Longtime User
I noticed it is kind of slow. Especially when connecting the socket. Should I keep the socket open for the life of the application, or do you open a socket and close it when you are done with it each time?
 
Upvote 0
Top