-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
97 lines (67 loc) · 1.97 KB
/
client.py
File metadata and controls
97 lines (67 loc) · 1.97 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import socket
import threading
import time
class Client:
def __init__(self):
self.client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.server_ip = "3.131.207.170"
self.Format = 'utf-8'
self.msg = []
self.prev_msg = []
#self.know = True
print(self.server_ip)
try:
self.client.connect((self.server_ip,9999))
except Exception as e:
print("server not available")
#self.is_recv = False
def ask_name(self):
self.send = self.name
self.client.send(self.send.encode(self.Format))
def ask_room(self,code,value_room):
choice = int(code)
val = value_room
#print(choice,value_room)
if(choice == 1):
#print("infor")
self.room_number = value_room
header = "header:1"
self.client.send(header.encode(self.Format))
time.sleep(0.1)
self.client.send(self.room_number.encode('utf-8'))
#print("end for")
elif(choice == 2):
self.room_number = value_room
header = "header:2"
self.client.send(header.encode(self.Format))
time.sleep(0.1)
self.client.send(self.room_number.encode('utf-8'))
else:
print("Not any thing")
value = self.client.recv(1024).decode('utf-8')
#print(type(value))
#print(value)
if((choice == 1) and (value == '0')):
print("room already exists")
print("enter valid code")
elif((choice == 2) and (value == '0')):
print("room does not exists")
print("enter_valid code")
if((choice == 1) and (value == '1')):
print(f"sucessfully created the room: {self.room_number}")
elif((choice == 2) and (value == '1')):
print(f"successfully entered the room {self.room_number}")
def send_msg(self,msg):
self.client.send(msg.encode(self.Format))
def recv_msg(self):
while True:
msg = self.client.recv(1024).decode(self.Format)
if(len(msg)>0):
#for i in self.msg:
#self.prev_msg = i
self.msg.append(msg)
#self.know = True
print(f"{msg}")
def make_thread(self):
self.thread1 = threading.Thread(target = self.recv_msg)
self.thread1.start()