Apparently in Python 2 you can concatenate bytes-like objects just like strings with the + sign.
How can I do that in Python 3?
In the below test code how do I correctly generate messagepart1 so it is a bytes-like object?
- Code: Select all
import base64, socket
myip = "10.51.2.40"
mymac = "aa:bb:cc:dd:ee:ff"
appstring = "iphone..iapp.samsung"
remotename = "Indigo Remote"
tvip = "10.51.9.10"
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((tvip, 55000))
ipencoded = base64.b64encode(bytes(myip,'UTF-8'))
macencoded = base64.b64encode(bytes(mymac,'UTF-8'))
remotename = base64.b64encode(bytes(remotename,'UTF-8'))
appstring = base64.b64encode(bytes(appstring,'UTF-8'))
messagepart1 = chr(0x64) + chr(0x00) + chr(len(ipencoded)) \
+ chr(0x00) + ipencoded \
+ chr(len(macencoded)) \
+ chr(0x00) \
+ macencoded \
+ chr(len(remotename)) \
+ chr(0x00) \
+ remotename
part1 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart1)) + chr(0x00) + messagepart1
sock.send(part1)
messagepart2 = chr(0xc8) + chr(0x00)
part2 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart2)) + chr(0x00) + messagepart2
sock.send(part2)