2018-10-24-day19作业

import socket
with open('./files/欢迎界面.txt','r',encoding='utf-8') as f:
welcome=f.read()
server=socket.socket()
server.bind(('10.7.156.62',8096))
server.listen(100)
print('开始监听')
welcome_re=welcome.encode('utf-8')

while True:
conversation,addr=server.accept()
while True:
message_re=conversation.recv(1024).decode('utf-8')
if message_re=='1':
with open('./files/123.jpg','br') as f:
content=f.read()
conversation.send(content)
conversation.close()
elif message_re=='2':
with open('./files/123.txt','br') as f:
content=f.read()
conversation.send(content)
elif message_re=='3':
break

import socket
while True:
with open('./files/欢迎界面.txt','r',encoding='utf-8') as f:
print(f.read())
client=socket.socket()
client.connect(('10.7.156.62',8096))
value=input('客服端:')
client.send(value.encode('utf-8'))
re_data=client.recv(1024)
data=bytes()
if value=='1':
while re_data:
data+=re_data
re_data=client.recv(1024)

    with open('./files/new.jpg', 'bw') as f:
        f.write(data)
    print('接收完成')
if value=='2':
    while re_data:
        data+=re_data
        re_data=client.recv(1024)

    with open('./files/new.txt', 'bw') as f:
        f.write(data)
    print('接收完成')
if value=='3':
    break

你可能感兴趣的:(2018-10-24-day19作业)