-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
49 lines (35 loc) · 1.05 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
import socket
def inet_connect(ip,serverport):
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((ip,serverport))
print("Connection Established with :",ip,":",serverport)
print("Wait...")
return s
def get_data():
data=input('Say something:')
return data
def rec(s):
data=s.recv(4096)
return data.decode('ASCII')
def send(data,s):
data=data.encode('ASCII')
s.send(data)
serverport=int(input("Enter Port:"))
ip=input("Enter IP:")
s=inet_connect(ip,serverport)
while True:
data=rec(s)
print("\t\t\tFriend:",data)
if data == "OK Bye Closing Connection..." :
print("Connection Is Closed.")
s.close()
break
data=get_data()
if data=="":
send(' ',s)
elif data =="exit" or data =="logout":
send("OK Bye Closing Connection...",s)
s.close()
break
send(data,s)
print("You:",data)