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

            一个色综合久久| 久久人人爽人爽人人爽av| 美女久久久久久| 国产AV影片久久久久久| 亚洲一区二区三区日本久久九| 国产精品欧美久久久天天影视| 久久综合九色综合网站| 99久久国产综合精品女同图片 | 欧美国产精品久久高清| 国产激情久久久久影院| 国产精久久一区二区三区| 久久久久香蕉视频| 久久久久99这里有精品10| 久久精品国产亚洲av麻豆蜜芽| 中文字幕无码精品亚洲资源网久久 | 美女久久久久久| 国产69精品久久久久观看软件| 中文字幕无码精品亚洲资源网久久| 亚洲精品乱码久久久久66| 99久久成人国产精品免费| 国产精品永久久久久久久久久| 欧美久久一级内射wwwwww.| 偷偷做久久久久网站| 久久天天躁狠狠躁夜夜躁2O2O| 久久美女网站免费| 国产99久久久国产精品小说| www久久久天天com| 久久精品国产亚洲AV不卡| 亚洲熟妇无码另类久久久| 国产精品青草久久久久福利99| 99久久精品免费看国产一区二区三区 | 97久久国产综合精品女不卡| 国内精品久久久久久野外| 亚洲国产小视频精品久久久三级 | 99久久综合国产精品免费| 久久久精品免费国产四虎| 久久免费视频1| 久久精品国产一区二区三区 | 久久精品成人国产午夜| 久久99精品久久久大学生| 国产999精品久久久久久|