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

            精品久久一区二区三区| 色狠狠久久综合网| 色综合久久久久无码专区| 一本一道久久a久久精品综合| 久久综合给合综合久久| 久久久一本精品99久久精品88| 久久久一本精品99久久精品88| 97久久天天综合色天天综合色hd| 精品熟女少妇aⅴ免费久久| 久久精品国产乱子伦| 久久精品国产秦先生| 2021国产精品久久精品| 99精品久久久久中文字幕| 久久国产成人精品国产成人亚洲| 国产成人久久精品一区二区三区| 丰满少妇人妻久久久久久4| 久久亚洲AV无码精品色午夜| 97精品伊人久久久大香线蕉| 无码久久精品国产亚洲Av影片| 久久av免费天堂小草播放| 久久精品国产网红主播| 国产精品久久久久久久人人看 | 精品久久久久久亚洲| 青青热久久国产久精品| 久久久综合九色合综国产| 日产精品久久久久久久| 久久99久国产麻精品66| 热久久视久久精品18| 久久影视综合亚洲| 久久精品无码av| 岛国搬运www久久| 91麻精品国产91久久久久| 韩国无遮挡三级久久| 久久99免费视频| 99久久久国产精品免费无卡顿| 久久久久99精品成人片欧美| 麻豆亚洲AV永久无码精品久久 | 久久综合九色综合精品| 77777亚洲午夜久久多喷| 精品熟女少妇av免费久久| 久久精品国产亚洲AV麻豆网站 |