-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
39 lines (33 loc) · 830 Bytes
/
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
import socket
import time
# build a socket
PORT=443
SERVER="localhost"
ADDR=(SERVER,PORT)
FORMAT="utf-8"
DISCONNECT_MESSAGE="!DISCONNECT"
def connect():
client=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)
return client
def send(client,msg):
message=msg.encode(FORMAT)
client.send(message)
# client=connect()
# send(client, "Testing")
# input()
# send(client,DISCONNECT_MESSAGE)
def start():
answer=input('Would you like to connect(yes/no)?')
if(answer.lower()!='yes'):
return
connection=connect()
while True:
msg=input("Message(q for quit): ")
if msg == 'q':
break
send(connection,msg)
send(connection,DISCONNECT_MESSAGE)
time.sleep(1)
print('Disconnected')
start()