作者:兜妈是我 | 来源:互联网 | 2023-07-20 19:26
1、Server端importsocketsksocket.socket()sk.bind((127.0.0.1,9000))sk.listen()conn,addrsk.acce
1、Server端
'''
'''
import socket
sk = socket.socket()
sk.bind(('127.0.0.1',9000))
sk.listen()
conn,addr = sk.accept()
print(addr)
while True:
ret = conn.recv(1024).decode('utf-8')
if ret == 'bye':
break
print(ret)
info = input('>>>')
conn.send(bytes(info,encoding='utf-8'))
conn.close()
sk.close()
2、Client端
#-*-coding:utf-8-*-
'''
client
'''
import socket
sk = socket.socket()
sk.connect(('127.0.0.1',9000))
while True:
info = input(">>>")
sk.send(bytes(info,encoding='utf-8'))
ret = sk.recv(1024).decode('utf-8')
print(ret)
if ret =='bye':
sk.send(b'bye')
break
sk.close()