forked from zense/Hackathon-Python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
78 lines (57 loc) · 1.47 KB
/
client.py
File metadata and controls
78 lines (57 loc) · 1.47 KB
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
73
74
75
76
77
78
import socket
import pickle
import threading
import sys
import time
class Client:
def __init__(self):
self.soc = socket.socket()
self.can_start = False
self.poss_ids = [1,2,3,4]
self.one = [0,0,0]
self.two = [0,0,0]
self.three = [0,0,0]
try:
self.soc.connect(("127.0.0.1",9845))
print("port lstest")
except Exception as e:
print("server unavailable")
def recv_id(self):
try:
self.ide = pickle.loads(self.soc.recv(1024))
print("id",self.ide)
except Exception as e:
print(e)
def send_cor(self,co_ordinates):
self.soc.send(pickle.dumps(co_ordinates))
def recv_is_alljoined(self):
joined = 0
try:
joined = pickle.loads(self.soc.recv(1024))
print(joined)
if(joined == "1"):
self.can_start = True
except Exception as e:
joined = 0
def recv_start_coordinates(self):
try:
self.start_cordinates = pickle.loads(self.soc.recv(1024))
print("coordinates recved")
print(self.start_cordinates)
except Exception as e:
print(e)
def recv_coorinates(self):
while True:
try:
self.one = pickle.loads(self.soc.recv(1024))
self.two = pickle.loads(self.soc.recv(1024))
self.three = pickle.loads(self.soc.recv(1024))
except Exception as e:
print(e)
#print("recved_cor",self.one,self.two,self.three)
def make_threads(self):
Thread = threading.Thread(target = self.recv_is_alljoined)
Thread.start()
def make_thread2(self):
t = threading.Thread(target = self.recv_coorinates)
t.start()