python 网络编程-01基础
python 网络编程
// 服务端 server.py
import socket
if __name__ == '__main__':
server = socket.socket()
server.bind(('127.0.0.1', 8000))
server.listen(5)
while True:
conn, addr = server.accept()
msg = conn.recv(1024)
print(msg)
answer = input('请输入:')
conn.send(answer.encode('utf-8'))
//客户端 client.py
import socket
if __name__ == '__main__':
client = socket.socket()
client.connect(('127.0.0.1', 8000))
client.send(b'hello')
msg = client.recv(1024)
print(msg.decode('utf-8'))
client.close()