2019-08-15 作业

只是实现了服务器的多线程

from socket import *
from threading import Thread


class ConnectionThread(Thread):
    def __init__(self, connect:socket, address):
        super().__init__()
        self.connect = connect
        self.address = address

    def run(self) -> None:
        self.create_connect()

    def create_connect(self):
        while True:
            print('listening')
            msg = "server"
            self.connect.send(msg.encode())
            re_data = self.connect.recv(1024)
            print(re_data.decode(encoding='utf-8'))



server = socket()
server.bind(('10.7.181.105', 9909))
server.listen(512)
c, a = server.accept()
t = ConnectionThread(c, a)
t.start()

你可能感兴趣的:(2019-08-15 作业)