-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.py
73 lines (61 loc) · 2.1 KB
/
server.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import threading
import socket
import sys
import pickle
def getMyIP():
mySock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySock.connect(('8.8.8.8', 80))
ip = mySock.getsockname()[0]
mySock.close()
return ip
class Server(threading.Thread):
def __init__(self, exitStatus):
threading.Thread.__init__(self)
self.frame = self.sample = None
self.clFrame = self.clSample = None
self.exitStatus = exitStatus
self.started = False
def run(self):
print 'Server started'
serverSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
IP = getMyIP()
print 'Your IP is ' + str(IP)
HOST = 8888
serverSock.bind((IP, HOST))
print 'Address binded, now listening'
serverSock.listen(1)
print 'Lisened'
clientSock, addr = serverSock.accept()
print 'client found'
print addr
counter = 0
SIZES = sys.getsizeof(pickle.dumps(self.getMySoundSample()))
SIZEF = sys.getsizeof(pickle.dumps(self.getMyImageFrame()))
while True:
print 'hello'
clientSock.send(pickle.dumps(self.getMySoundSample()))
clientSock.send(pickle.dumps(self.getMyImageFrame()))
soundSample = clientSock.recv(SIZES)
soundSample = pickle.loads(soundSample)
imageFrame = clientSock.recv(SIZEF)
imageFrame = pickle.loads(imageFrame)
self.setClientImageFrame(imageFrame)
self.setClientSoundSample(soundSample)
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 getClientImageFrame(self):
return self.clFrame
def getClientSoundSample(self):
return self.clSample
def setClientImageFrame(self, frame):
self.clFrame = frame
def setClientSoundSample(self, sample):
self.clSample = sample