-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.py
55 lines (45 loc) · 1.61 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import threading
import socket
import sys
import pickle
class Client(threading.Thread):
def __init__(self, addr):
threading.Thread.__init__(self)
self.addr = addr
self.frame = self.sample = 0
self.servFrame = self.servSample = 0
self.started = False
def run(self):
print 'Client started'
clientSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientSock.connect(self.addr)
counter = 0
SIZES = sys.getsizeof(pickle.dumps(self.getMySoundSample()))
SIZEF = sys.getsizeof(pickle.dumps(self.getMyImageFrame()))
while True:
soundSample = clientSock.recv(SIZES)
soundSample = pickle.loads(soundSample)
imageFrame = clientSock.recv(SIZEF)
imageFrame = pickle.loads(imageFrame)
self.setServImageFrame(imageFrame)
self.setSetSoundSample(soundSample)
clientSock.send(pickle.dumps(self.getMySoundSample()))
clientSock.send(pickle.dumps(self.getMyImageFrame()))
counter += 1
self.started = True
def setMySoundSample(self, sample):
self.sample = sample
def getMySoundSample(self):
return self.sample
def setMyImageFrame(self, frame):
self.frame = frame
def getMyImageFrame(self):
return self.frame
def getServImageFrame(self):
return self.servFrame
def getServSoundSample(self):
return self.servSample
def setServImageFrame(self, frame):
self.servFrame = frame
def setSetSoundSample(self, sample):
self.servSample = sample