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

            亚洲&#228;v永久无码精品天堂久久 | 国产午夜电影久久| 久久天天躁狠狠躁夜夜2020老熟妇 | 日产久久强奸免费的看| 久久久久久久波多野结衣高潮| 国产精品一区二区久久精品涩爱| 国产精品久久久久久久久软件 | 色偷偷888欧美精品久久久| 久久国产精品国语对白| 久久人人爽人人爽人人片AV东京热| 伊人久久久AV老熟妇色| 国产精品综合久久第一页| 99久久国产精品免费一区二区| 久久亚洲精品中文字幕三区| 久久久久亚洲AV无码观看| 国产一级持黄大片99久久| 7777精品伊人久久久大香线蕉| 久久se精品一区精品二区| 欧美日韩精品久久免费| 精品久久久久久无码人妻热| 人人狠狠综合久久88成人| 中文成人无码精品久久久不卡| 久久精品免费观看| 色8久久人人97超碰香蕉987| 思思久久好好热精品国产| 国产AV影片久久久久久| 久久九九亚洲精品| 精品国产一区二区三区久久| 久久精品一区二区三区AV| 亚洲v国产v天堂a无码久久| 久久99精品久久久久久噜噜| 亚洲国产精品久久久久| 久久精品无码一区二区三区| 国产精品一区二区久久不卡| 欧美喷潮久久久XXXXx| 亚洲AV无码久久精品蜜桃| 伊人久久大香线焦AV综合影院| 亚洲精品无码成人片久久| 伊人久久大香线焦AV综合影院 | 97久久精品国产精品青草| 69国产成人综合久久精品|