• <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| 中文字幕无码久久精品青草 | 精品久久久久香蕉网| 久久精品国产精品亚洲毛片| 99久久精品费精品国产一区二区| 久久国产精品久久国产精品| 热RE99久久精品国产66热| 一本色综合网久久| 亚洲成人精品久久| 久久无码高潮喷水| 国内精品欧美久久精品| 中文无码久久精品| 久久久久国产精品麻豆AR影院| 亚洲精品美女久久久久99| 久久青青草原国产精品免费 | 久久午夜夜伦鲁鲁片免费无码影视| 狠狠色婷婷久久综合频道日韩| 色综合久久综精品| 久久久亚洲欧洲日产国码二区| 婷婷久久综合九色综合绿巨人| 色偷偷888欧美精品久久久| 国产精品99久久久精品无码| 久久人人超碰精品CAOPOREN | 国产精品久久久久久久久免费| 亚洲国产高清精品线久久| yellow中文字幕久久网| 777米奇久久最新地址| 久久午夜夜伦鲁鲁片免费无码影视| 久久99久久成人免费播放| 秋霞久久国产精品电影院| 国产精品久久久久久一区二区三区| 久久天天婷婷五月俺也去| 青青热久久国产久精品 | 97久久婷婷五月综合色d啪蜜芽 | 国产精品免费久久久久久久久| 久久久久久久97| 99久久免费国产特黄| 91精品国产色综合久久| 国产韩国精品一区二区三区久久| 久久精品国产亚洲77777| 狠狠色婷婷综合天天久久丁香|