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

            久久伊人五月丁香狠狠色| 久久精品无码一区二区三区日韩 | 激情久久久久久久久久| 久久亚洲高清观看| 久久亚洲精品中文字幕三区| 97久久超碰国产精品2021| 国产高潮国产高潮久久久91| 国产亚洲精品久久久久秋霞| 精品一区二区久久久久久久网站| 婷婷国产天堂久久综合五月| 国产Av激情久久无码天堂| 国产精品久久久久一区二区三区| 久久国产一片免费观看| 久久无码精品一区二区三区| 国产精品岛国久久久久| 国产精品免费久久久久电影网| 亚洲婷婷国产精品电影人久久| 久久91精品国产91久久小草| 亚洲精品NV久久久久久久久久| 久久66热人妻偷产精品9| 理论片午午伦夜理片久久| 99精品国产在热久久无毒不卡| 久久激情亚洲精品无码?V| av无码久久久久久不卡网站| 久久无码专区国产精品发布| 超级碰久久免费公开视频| 人人狠狠综合久久88成人| 亚洲AV日韩精品久久久久久| 久久这里只有精品首页| 99久久国产亚洲综合精品| 国产成人精品久久| 91精品国产高清久久久久久io| 久久久精品久久久久影院| 久久国产福利免费| 久久中文娱乐网| 国产一区二区三精品久久久无广告 | 精品午夜久久福利大片| 激情伊人五月天久久综合| 久久九九精品99国产精品| 久久久精品国产亚洲成人满18免费网站| 久久精品国产99久久久古代 |