Use Msgpack module in BroadcastServer plugin

This commit is contained in:
shortcutme 2019-03-16 02:09:27 +01:00
parent 8ab9b06185
commit 8c5c3cb7a6
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -3,10 +3,9 @@ import logging
import time import time
from contextlib import closing from contextlib import closing
import msgpack
from Debug import Debug from Debug import Debug
from util import UpnpPunch from util import UpnpPunch
from util import Msgpack
class BroadcastServer(object): class BroadcastServer(object):
@ -69,7 +68,7 @@ class BroadcastServer(object):
break break
try: try:
message = msgpack.unpackb(data) message = Msgpack.unpack(data)
response_addr, message = self.handleMessage(addr, message) response_addr, message = self.handleMessage(addr, message)
if message: if message:
self.send(response_addr, message) self.send(response_addr, message)
@ -93,7 +92,7 @@ class BroadcastServer(object):
self.log.debug("Send to %s: %s" % (addr, message_part["cmd"])) self.log.debug("Send to %s: %s" % (addr, message_part["cmd"]))
with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock: with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msgpack.packb(message_part), addr) sock.sendto(Msgpack.pack(message_part), addr)
def getMyIps(self): def getMyIps(self):
return UpnpPunch._get_local_ips() return UpnpPunch._get_local_ips()
@ -114,7 +113,7 @@ class BroadcastServer(object):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.bind((my_ip, 0)) sock.bind((my_ip, 0))
sock.sendto(msgpack.packb(message), addr) sock.sendto(Msgpack.pack(message), addr)
except Exception as err: except Exception as err:
self.log.warning("Error sending broadcast using ip %s: %s" % (my_ip, err)) self.log.warning("Error sending broadcast using ip %s: %s" % (my_ip, err))