• <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

            靜以修身,儉以養(yǎng)德,非澹薄無以明志,非寧靜無以致遠。
            隨筆 - 398, 文章 - 0, 評論 - 196, 引用 - 0
            數(shù)據(jù)加載中……

            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 閱讀(275) 評論(0)  編輯 收藏 引用 所屬分類: python

            亚洲?V乱码久久精品蜜桃 | 亚洲中文字幕无码久久2017| 一97日本道伊人久久综合影院| 久久精品亚洲欧美日韩久久| 久久久久人妻精品一区三寸蜜桃 | av无码久久久久久不卡网站| A级毛片无码久久精品免费| 久久综合九色欧美综合狠狠| 日本强好片久久久久久AAA| 久久久久久国产精品无码下载| 99久久精品国产一区二区| 国产精品激情综合久久| 精品无码久久久久国产动漫3d| 日韩一区二区久久久久久| 思思久久99热只有频精品66| 99久久777色| 久久人妻无码中文字幕| 老司机午夜网站国内精品久久久久久久久| 久久精品人人槡人妻人人玩AV| 一本大道久久a久久精品综合 | 久久久www免费人成精品| 精品视频久久久久| 91精品无码久久久久久五月天| 久久精品国产久精国产一老狼| 久久久久国产一区二区| 久久99国产综合精品| 欧美黑人激情性久久| 久久免费看黄a级毛片| 久久亚洲日韩看片无码| 精品国产婷婷久久久| 精品人妻伦一二三区久久| 国产成人久久777777| 91精品国产91热久久久久福利| 亚洲狠狠久久综合一区77777| 国产亚洲精久久久久久无码| 99久久er这里只有精品18| 97久久超碰成人精品网站| 国产精品禁18久久久夂久| 久久综合欧美成人| 青青青伊人色综合久久| 日韩美女18网站久久精品|