-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.py
54 lines (40 loc) · 1.1 KB
/
Player.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
from socket import *
import pickle
from threading import *
player = socket(AF_INET, SOCK_STREAM)
player.connect(("26.52.80.182", 9997))
lock = Lock()
print("\033[40m{}".format(""))
def mutar():
global lock
lock.acquire()
print("ESPERE A VEZ DO OUTRO JOGADOR E NÃO DIGITE NADA")
while True:
msg = pickle.loads(player.recv(4096))
if msg[0] == 1:
print(msg[1])
elif msg[0] == 2:
player.send(pickle.dumps(input()))
break
elif msg[0] == 3:
print("ESPERE A VEZ DO OUTRO JOGADOR E NÃO DIGITE NADA")
elif msg[0] == 0:
player.close()
lock.release()
def handle_request(req):
if req[0] == 1:
print(req[1])
elif req[0] == 2:
player.send(pickle.dumps(input()))
while True:
request = pickle.loads(player.recv(4096))
if request[0] == 0:
player.close()
print("Foi bom tê-lo conosco ☺")
break
elif request[0] == 3:
t2 = Thread(target=mutar())
t2.start()
t2.join()
t = Thread(target=handle_request(request))
t.start()