课后作业 day29

课后作业day29

#clinet
import socket

client = socket.socket()
client.connect(('192.168.13.254',15555))

while True:
    msg = input('get_upper:').strip()

    if not msg:
        continue

    if msg == 'q':
        break

    client.send(msg.encode('utf8'))
    re_data = client.recv(1024)
    print(re_data)
#server
import socket
import threading

server = socket.socket()
server.bind(('192.168.13.254',15555))
server.listen(5)

def task(conn):
    while True:
        data = conn.recv(1024)
        print(data)
        conn.send(data.upper())

if __name__ == '__main__':
    while True:
        conn, addr = server.accept()
        print(f'{addr}成功连接')
        p = threading.Thread(target=task, args=(conn,))
        p.start()
posted @ 2019-10-22 21:51  simple123  阅读(92)  评论(0编辑  收藏  举报