From af3e084f8f27f478d372d2906a05d9b289833cb4 Mon Sep 17 00:00:00 2001 From: Grissess Date: Sun, 14 Jun 2015 03:46:37 -0400 Subject: Added client.py --- broadcast.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'broadcast.py') diff --git a/broadcast.py b/broadcast.py index 0483a67..f244aa6 100644 --- a/broadcast.py +++ b/broadcast.py @@ -5,6 +5,8 @@ import time import xml.etree.ElementTree as ET import threading +from packet import Packet, CMD + PORT = 13676 if len(sys.argv) > 2: factor = float(sys.argv[2]) @@ -13,22 +15,6 @@ else: print 'Factor:', factor -class Packet(object): - def __init__(self, cmd, *data): - self.cmd = cmd - self.data = data - if len(data) >= 8: - raise ValueError('Too many data') - self.data = list(self.data) + [0] * (8-len(self.data)) - def __str__(self): - return struct.pack('>L'+('L'*len(self.data)), self.cmd, *self.data) - -class CMD: - KA = 0 # No important data - PING = 1 # Data are echoed exactly - QUIT = 2 # No important data - PLAY = 3 # seconds, microseconds, frequency (Hz), amplitude (0-255) - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) -- cgit v1.2.3-70-g09d2