-
Notifications
You must be signed in to change notification settings - Fork 8
/
client.py
executable file
·77 lines (62 loc) · 1.85 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import socket
import time
import os
import platform
import threading
class client():
''' node for sending request to server
to iniate a communication '''
#__________initializing a node for TCP communication___________
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#__________ Our node server information _______________
def __init__(self):
while True:
self.server_ip = input('Enter server_ip: ')
self.server_port = 12345
if len(self.server_ip.split('.'))<4:
continue
break
print('Finding connection')
time.sleep(1)
@property
def make_connection(self):
''' Sending connection request to the server node '''
while True:
try:
server = (self.server_ip, self.server_port)
self.client_socket.connect(server)
print('Connection succesful made to the server')
return True
except:
print('..');time.sleep(0.1)
print('..'*2);time.sleep(0.1)
print('..'*6);time.sleep(0.1)
if platform.system().lower().startswith('win'):
os.system('cls')
continue
os.system('clear')
def send_sms(self, msg):
''' Sending the message to the connected
Sever '''
self.client_socket.send(msg.encode())
def receive_sms(self):
''' Receiving message from the node server'''
while True:
data = ''
data = self.client_socket.recv(1024).decode()
'''Printing sms received from the server '''
time.sleep(0.001)
print(data)
def chat_room(self):
if self.make_connection:
Receiving_cio = threading.Thread(target=self.receive_sms)
Receiving_cio.daemon = True
Receiving_cio.start()
while True:
message = input()
message = "\nclient:{}\n".format(message)
self.send_sms(message)#Client replying
continue
if __name__ == '__main__':
Client = client()
Client.chat_room()