美文网首页
day017 作业 08-06

day017 作业 08-06

作者: Yehao_ | 来源:发表于2018-08-07 19:51 被阅读0次

Server

import socket


IP = '10.7.181.90'
PORT = 12345
if __name__ == '__main__':
    server = socket.socket()
    server.bind((IP, PORT))
    server.listen(50)
    while True:
        conversation, addr = server.accept()
        while True:
            msg_send = input('>>>')
            conversation.send(msg_send.encode())
            if isinstance(msg_send, bytes):
                with open('./serverSendFile', 'rb') as f:
                    data_send = f.read()
                conversation.send(data_send)

            msg_recv = conversation.recv(1024)
            if msg_recv == '拜拜':
                conversation.close()
            else:
                print(msg_recv.decode())
            data = bytes()
            if isinstance(msg_recv, bytes):
                while msg_recv:
                    data += msg_recv
                    msg_recv = conversation.recv(1024)
                with open('./serverRecvFile', 'wb') as f:
                    f.write(data)
        conversation.close()

Client

import socket


IP = '10.7.181.90'
PORT = 12345
if __name__ == '__main__':
    client = socket.socket()
    client.connect((IP, PORT))
    while True:
        data_recv = client.recv(1024)
        data = bytes()
        msg_send = input('>>>')
        if isinstance(msg_send, bytes):
            with open('./serverSendFile', 'rb') as f:
                data_send = f.read()
            client.send(data_send)

        if isinstance(data_recv, bytes):
            while data_recv:
                data += data_recv
                data_recv = client.recv(1024)
            with open('./clientRecvFile', 'wb') as f:
                f.write(data)
        else:
            print(data_recv.decode())
        if data_recv == '拜拜':
            client.close()

        client.close()

相关文章

  • day017 作业 08-06

    Server Client

  • BM运营官-【心得05】DAY017-by Bella

    DAY017 by Bella 作业要求:输出第五课学习心得听了桐心老师关于社群运营官《成本控制能力》的学习,我学...

  • Day017

    Smiling without a word is an open-minded, pain without wo...

  • Day017

    There are two important things in life.The first thing is...

  • DAY017

    This is my son’s favorite cartoon. Yesterday I came back ...

  • 08-06

    早安! 昨天跟着一群优力普家人,到沙腰檀香岛去拜关公。确实,在这公司,我能找到凝聚的力量。感受到彼此之间的关注与力...

  • 08-06=_=

    继续继续✌✌ 一、日常任务 1.早起 在7点前起床,并在营里打卡,完成。 9点之前在营里做#晨间分享#,完成。 2...

  • 08-06

    [2019]217-11/365 1、人的缘故 之前励志组有讨论过,为什么到哪都是忙到没有个人时间,到底是人的缘故...

  • 冯祥的祖传妙药

    冯祥的祖传妙药 08-06 智慧故事 约 879 字 预计阅读 1 分钟 明代万历年间...

  • 2021.11.18

    02:34-02:46 06:08-06:22 10:19-10:35 15:01-15:20 17:36-17:...

网友评论

      本文标题:day017 作业 08-06

      本文链接:https://www.haomeiwen.com/subject/nytzvftx.html