socket
客户端:
import socket
sk=socket.socket()
address = ('127.0.0.1',8000)
sk.connect(address)
while True:
inp = input('>>>')
sk.sendall(bytes(inp,'utf-8'))
if inp=='exit':
break
data = sk.recv(1024)
data = str(data,'utf-8')
print(data)
sk.close()
服务器:
# !usr/bin/python3
#-*- utf-8 -*-
# Author:huang
# @time
import socket
sk=socket.socket()
address = ('127.0.0.1',8000)
sk.bind(address)
sk.listen(4)
conn,dir=sk.accept()
while True:
data = conn.recv(1024)
data = str(data,'utf-8')
print(data)
inp = input('>>>')
conn.sendall(bytes(inp,'utf-8'))
conn.close()