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

            亚洲成色www久久网站夜月| 亚洲精品乱码久久久久66| 2021久久精品国产99国产精品| 国产精品美女久久久m| 狠狠狠色丁香婷婷综合久久五月| 99久久精品免费看国产一区二区三区| 久久se精品一区精品二区| 久久亚洲天堂| 欧美久久精品一级c片片| 中文字幕无码久久精品青草| 久久久一本精品99久久精品66| 91精品国产综合久久香蕉| 怡红院日本一道日本久久 | 亚洲欧美一区二区三区久久| 久久露脸国产精品| 99re久久精品国产首页2020| 人妻丰满?V无码久久不卡| MM131亚洲国产美女久久| 一本大道久久东京热无码AV | 久久人人爽人人爽人人片AV东京热| 麻豆一区二区99久久久久| 久久精品国产WWW456C0M| 久久久久人妻精品一区二区三区| 国产精品日韩深夜福利久久| 狠狠色婷婷久久综合频道日韩| 久久se精品一区二区影院| 久久最新精品国产| 成人久久精品一区二区三区| 亚洲AV日韩AV永久无码久久| 综合久久一区二区三区| 精品免费久久久久国产一区| 国产国产成人精品久久| 久久国产亚洲精品无码| 天天躁日日躁狠狠久久| 久久免费看黄a级毛片| 亚州日韩精品专区久久久| 久久影视国产亚洲| 热久久国产欧美一区二区精品| 久久久久这里只有精品| 国产视频久久| 中文字幕精品久久久久人妻|