-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client 2.py
64 lines (54 loc) · 1.61 KB
/
Client 2.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
from socket import *
def chat(c):
ch = input('How many Converstation Do you want to Make')
c.send(bytes(ch, 'utf-8'))
m = c.recv(1024).decode()
n = int(m)
return n
def sender(c):
msg = input('Enter a message')
c.send(bytes(msg, 'utf-8'))
print('Sended......')
def receiver(c):
print('Waiting for reply......')
print(c.recv(1024).decode(),':',c.recv(1024).decode())
def option(c):
try:
print('1.Send First\n 2.Receive First')
op = int(input('Please enter you Choice'))
except ValueError:
print('Please enter your choice in INTEGER')
la= int(input('Enter here'))
op=la
except Exception:
print('Something Went Wrong......\nPlease Rerun your Program')
finally:
o=str(op)
c.send(bytes(o, 'utf-8'))
def rec(c):
ch = c.recv(1024).decode()
return ch
c = socket()
c.connect(('localhost', 9999))#Please Enter IP address instead of 'localhost' to connect with Server
print('Connected With Server')
name = input('Enter your Name')
c.send(bytes(name, 'utf-8'))
print(c.recv(1024).decode())
name = c.recv(1024).decode()
print('Online:', name)
n = chat(c)
option(c)
ch = rec(c)
if ch == 'Same':
print('You entered the Same input as your Partner')
print('Please Rerun the Program and Enter the Alternative Input')
else:
if ch == 'S' or ch == 's':
for i in range(n):
sender(c)
receiver(c)
elif ch == 'R' or ch == 'r':
for i in range(n):
receiver(c)
sender(c)
print(c.recv(1024).decode())