-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient3.py
More file actions
34 lines (25 loc) · 677 Bytes
/
Copy pathclient3.py
File metadata and controls
34 lines (25 loc) · 677 Bytes
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
import socket
import threading
ip = '127.0.0.1' # localhost
port = 9999
clientSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientSock.connect((ip, port)) # connect to the socket!!
print('Connected!')
# recv : receive the data, send : send the data
def recv():
while True:
try:
msg1 = clientSock.recv(1024).decode('utf-8')
print(msg1)
except:
clientSock.close()
break
def send():
while True:
msg = input()
clientSock.send(msg.encode('utf-8'))
# threading
sender = threading.Thread(target=send)
receiver = threading.Thread(target=recv)
sender.start()
receiver.start()