• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Benjamin

            靜以修身,儉以養德,非澹薄無以明志,非寧靜無以致遠。
            隨筆 - 397, 文章 - 0, 評論 - 196, 引用 - 0
            數據加載中……

            python tcp client

            import threading
            import socket
            # ------------------------Client------------------------
            class Client:
            threadCounter = 0 # Give number to threads
            def __init__(self,host,port):
            self.connection = socket.socket() # Create a socket object
            self.host = host#socket.gethostname() # Get local machine name
            self.port = port # Reserve a port for your service.
            def connect(self):
            self.connection.connect((self.host, self.port))
            # ------------------------ReaderThread------------------------
            self.threadCounter += 1
            readerThread = ReaderThread(self.threadCounter, "Thread-" + str(self.threadCounter), self.connection)
            readerThread.start()
            # ------------------------WriterThread------------------------
            self.threadCounter += 1
            writerThread = WriterThread(self.threadCounter, "Thread-" + str(self.threadCounter), self.connection)
            writerThread.start()
            # ------------------------ReaderThread------------------------
            class ReaderThread(threading.Thread):
            def __init__(self, threadID, name, connection):
            threading.Thread.__init__(self)
            self.threadID = threadID
            self.name = name
            self.connection = connection
            def run(self):
            global exitFlag
            global wait
            print("Starting ReaderThread " + str(self.threadID) + " " + self.name)
            while exitFlag:
            data = self.connection.recv(1024)
            if data:
            print(data)
            if data[0:3] == "BYE":
            exitFlag = False
            if data[0:3] == "NOW":
            self.connection.send("TNX")
            wait = False
            # ------------------------WriterThread------------------------
            class WriterThread(threading.Thread):
            def __init__(self, threadID, name, connection):
            threading.Thread.__init__(self)
            self.threadID = threadID
            self.name = name
            self.connection = connection
            def run(self):
            global exitFlag
            global wait
            print("Starting WriterThread " + str(self.threadID) + " " + self.name)
            while exitFlag:
            if not wait:
            request = "Please enter what you want? "
            self.connection.send(request.encode())
            wait = True
            # ------------------------Main Program Functionality------------------------
            #用法示例
            exitFlag = True
            wait = False
            client = Client('127.0.0.1',8888)
            client.connect()

            posted on 2020-01-03 19:32 Benjamin 閱讀(264) 評論(0)  編輯 收藏 引用 所屬分類: python

            亚洲美日韩Av中文字幕无码久久久妻妇| 久久精品人妻中文系列| 国产精品久久久久…| 一本久久久久久久| 久久久久亚洲AV无码观看| 国产精品欧美久久久天天影视| 久久免费视频一区| 国内精品久久久久伊人av| 手机看片久久高清国产日韩| 国产Av激情久久无码天堂| 婷婷久久综合九色综合绿巨人 | 久久综合久久鬼色| 麻豆成人久久精品二区三区免费 | 99热都是精品久久久久久| 久久99九九国产免费看小说| 成人亚洲欧美久久久久| 久久亚洲AV成人出白浆无码国产| 久久93精品国产91久久综合| 久久精品免费一区二区三区| 无码人妻少妇久久中文字幕蜜桃| 久久亚洲国产成人影院网站| 草草久久久无码国产专区| 久久国产精品无码一区二区三区| 2021国内久久精品| 一本久道久久综合狠狠躁AV| 久久男人中文字幕资源站| 91精品国产91久久久久久青草| 久久w5ww成w人免费| 精品人妻久久久久久888| 久久久免费精品re6| 天堂久久天堂AV色综合| 亚洲国产欧美国产综合久久| 久久久久国产精品嫩草影院| 久久人人爽人人人人片av| 国内精品久久久久影院老司| 亚洲日本va午夜中文字幕久久| 久久久久亚洲精品男人的天堂| 日本久久中文字幕| 国产精品久久新婚兰兰| 久久香蕉国产线看观看精品yw | 亚洲精品无码专区久久同性男|