I created a RoByteArray using the SDK specs and I'm sending to the server the authentication but the server is returning -1 all the time..
Any tips?
😄
Sub Main()
m.msgPort = CreateObject("roMessagePort")
screen = CreateObject("roParagraphScreen")
screen.setMessagePort(m.msgPort)
screen.show()
print "Main: starting Roku Sling Player"
BoxInfo = getBox("YOUR ID")
setVariables()
setAdress(BoxInfo.DeviceAddress, BoxInfo.DevicePort)
if Connect(true, "YOUR PASSWORD") then
print ("Connected")
else
print ("error")
end if
End Sub
function getBox(id as String) as Dynamic
this = CreateObject("roAssociativeArray")
port = CreateObject("roMessagePort")
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(port)
screen.SetTitle("Example")
TextTransfer=CreateObject("roUrlTransfer")
TextTransfer.SetUrl("http://srs.slingmedia.com/getDeviceInfo.asp?id=" + id)
SlingBoxInfo=TextTransfer.GetToString()
pa = Instr(SlingBoxInfo,"DeviceAddress=")
if pa > 0 then
pa = pa + 14
i=0
while mid(SlingBoxInfo,pa+i,1) <> "<"
i=i+1
end while
DeviceAddress= mid(SlingBoxInfo,pa,i)
endif
pp = Instr(SlingBoxInfo,"DevicePort=")
if pp > 0 then
pp = pp + 11
i=0
while mid(SlingBoxInfo,pp+i,1) <> "<"
i=i+1
end while
DevicePort= mid(SlingBoxInfo,pp,i)
endif
this.DeviceAddress = DeviceAddress
this.DevicePort = 5001
return this
End function
Sub setVariables()
m.socCommunication = createobject("roStreamSocket")
m.socStream = createobject("roStreamSocket")
m.socAddress = createobject("roSocketAddress")
m.szAddress = ""
m.uiPort = 0
m.usCode = 0
m.usSequence = 0
m.iChannel = -1
m.iInput = -1
m.usHeader = HexToInteger("0101") '// Always 0x0101
m.usCode = 0 '// Grabbed from the first packet from the Slingbox then
m.usMessageID = 0 '// Unique number to identify the message
m.usVar4 = 0 '// Always 0
m.usSequence = 0 '// Sequencial number (answer will have the same number)
m.usDirection = HexToInteger("8000") '// 0 from Slingbox and 0x8000 from software
m.usVar7 = 0
m.usVar8 = 0
m.usSize = 0 '// Size of the buffer (without header)
m.usEncoded = 0 '// 0x2000 if buffer is encoded
m.usVar11 = 0
m.usVar12 = 0
m.usVar13 = 0
m.usVar14 = 0
m.usVar15 = 0
m.usVar16 = 0
m.uiUnknown = HexToInteger("00000000")
m.usAccess = CreateObject("roByteArray")
m.usAccess.setresize(16, false)
m.usPassword = CreateObject("roByteArray")
m.usPassword.setresize(16, false)
m.usID = CreateObject("roByteArray")
m.usID.setresize(66, false)
m.usID.FromAsciiString("Slingbox")
m.SlingBoxMessageIn = CreateObject("roByteArray")
m.SlingBoxMessageIn.setresize(198, false)
m.SlingBoxMessageOut = CreateObject("roByteArray")
m.SlingBoxMessageOut.setresize(198, false)
End Sub
Sub setAdress(saddress as string, sport as integer)
m.DeviceAddress = saddress
m.DevicePort = sport
End Sub
function Connect(isAdmin as boolean, szPassword as string) as boolean
if m.socCommunication.isConnected() then
m.socCommunication.setMessagePort(invalid)
return false
end if
m.socAddress.setAddress(m.DeviceAddress)
m.socAddress.setPort(m.DevicePort)
m.socCommunication.setSendToAddress(m.socAddress)
m.socCommunication.connect()
szString = "GET /stream.asf HTTP/1.1" + chr(13) + chr(10) + "Accept: */*" + chr(13) + chr(10) + "Pragma: Sling-Connection-Type=Control, Session-Id=0" + chr(13) + chr(10) + chr(13) + chr(10)
print "send string"; m.socCommunication.sendStr(szString); " bytes"
port = CreateObject("roMessagePort")
m.socCommunication.setMessagePort(port)
m.socCommunication.notifyReadable(true)
msg = wait(60 * 1000, port)
if m.socCommunication.isReadable() = false
m.socCommunication.setMessagePort(invalid)
return false
end if
m.usCode = 0
m.usSequence = 0
m.iChannel = -1
m.iInput = -1
if isAdmin = true then
m.usAccess.FromAsciiString("admin")
end if
m.usPassword.FromAsciiString(szPassword)
m.usHeaderBA = rdINTtoBA2(m.usHeader)
fillMessage(0, m.usHeaderBA)
m.usCodeBA = rdINTtoBA2(m.usCode)
fillMessage(2, m.usCodeBA)
m.usMessageIDBA = rdINTtoBA2(m.usMessageID)
fillMessage(4, m.usMessageIDBA)
m.usVar4BA = rdINTtoBA2(m.usVar4)
fillMessage(6, m.usVar4BA)
m.usSequenceBA = rdINTtoBA2(m.usSequence)
fillMessage(8, m.usSequenceBA)
m.usDirectionBA = rdINTtoBA2(m.usDirection)
fillMessage(10, m.usDirectionBA)
m.usVar7BA = rdINTtoBA2(m.usVar7)
fillMessage(12, m.usVar7BA)
m.usVar8BA = rdINTtoBA2(m.usVar8)
fillMessage(14, m.usVar8BA)
m.usSizeBA = rdINTtoBA2(m.usSize)
fillMessage(16, m.usSizeBA)
m.usEncodedBA = rdINTtoBA2(m.usEncoded)
fillMessage(18, m.usEncodedBA)
m.usVar11BA = rdINTtoBA2(m.usVar11)
fillMessage(20, m.usVar11BA)
m.usVar12BA = rdINTtoBA2(m.usVar12)
fillMessage(22, m.usVar12BA)
m.usVar13BA = rdINTtoBA2(m.usVar13)
fillMessage(24, m.usVar13BA)
m.usVar14BA = rdINTtoBA2(m.usVar14)
fillMessage(26, m.usVar14BA)
m.usVar15BA = rdINTtoBA2(m.usVar15)
fillMessage(28, m.usVar15BA)
m.usVar16BA = rdINTtoBA2(m.usVar16)
fillMessage(30, m.usVar16BA)
m.uiUnknownBA = rdINTtoBA(m.uiUnknown)
fillMessage(34, m.uiUnknownBA)
m.usAccessBA = m.usAccess
fillMessage(50, m.usAccessBA)
m.usPasswordBA = m.usPassword
fillMessage(66, m.usPasswordBA)
m.usIDBA = m.usID
fillMessage(132, m.usIDBA)
m.socCommunication.setMessagePort(invalid)
m.socCommunication.notifyReadable(false)
m.socCommunication.Send(m.SlingBoxMessageOut, 0, m.SlingBoxMessageOut.Count())
port1 = CreateObject("roMessagePort")
m.socCommunication.setMessagePort(port1)
m.socCommunication.notifyReadable(true)
msg = wait(60 * 1000, port1)
input = m.socCommunication.receive(m.SlingBoxMessageIn, 0, m.socCommunication.getCountRcvBuf())
return true
End function
Sub fillMessage(entry as Integer, ba as Object)
For i=0 to ba.Count() - 1
m.SlingBoxMessageOut.setEntry(i+entry,ba[i])
End For
End Sub