當前位置: 首頁>>代碼示例>>Python>>正文


Python QtNetwork.QTcpSocket方法代碼示例

本文整理匯總了Python中PyQt5.QtNetwork.QTcpSocket方法的典型用法代碼示例。如果您正苦於以下問題:Python QtNetwork.QTcpSocket方法的具體用法?Python QtNetwork.QTcpSocket怎麽用?Python QtNetwork.QTcpSocket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.QtNetwork的用法示例。


在下文中一共展示了QtNetwork.QTcpSocket方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def __init__(self, socket: QtNetwork.QTcpSocket = None):
        """
        Initializes the extended TCP socket. Either wraps around an existing socket or creates its own and resets
        the number of bytes written.

        :param socket: An already existing socket or None if none is given.
        """
        super().__init__()

        # new QTcpSocket() if none is given
        if socket is not None:
            self.socket = socket
        else:
            self.socket = QtNetwork.QTcpSocket()

        # some wiring, new data is handled by _receive()
        self.socket.readyRead.connect(self._receive)
        self.socket.error.connect(self.error)
        self.socket.connected.connect(self.connected)
        self.socket.disconnected.connect(self.disconnected)
        self.socket.bytesWritten.connect(self.count_bytes_written)

        self.bytes_written = 0 
開發者ID:Trilarion,項目名稱:imperialism-remake,代碼行數:25,代碼來源:network.py

示例2: connect

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def connect(self, remoteAddress, port):
        """Establishes a session with the debugger"""
        self.socket = QTcpSocket()
        if remoteAddress is None:
            self.socket.connectToHost(QHostAddress.LocalHost, port)
        else:
            self.socket.connectToHost(remoteAddress, port)
        if not self.socket.waitForConnected(1000):
            raise Exception('Cannot connect to the IDE')
        self.socket.setSocketOption(QAbstractSocket.KeepAliveOption, 1)
        self.socket.setSocketOption(QAbstractSocket.LowDelayOption, 1)
        self.socket.disconnected.connect(self.__onDisconnected) 
開發者ID:SergeySatskiy,項目名稱:codimension,代碼行數:14,代碼來源:clientbase_cdm_dbg.py

示例3: connect

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def connect(self, remoteAddress, port):
        """Establishes a connection with the IDE"""
        self.__socket = QTcpSocket()
        if remoteAddress is None:
            self.__socket.connectToHost(QHostAddress.LocalHost, port)
        else:
            self.__socket.connectToHost(remoteAddress, port)
        if not self.__socket.waitForConnected(1000):
            raise Exception('Cannot connect to the IDE')
        self.__socket.setSocketOption(QAbstractSocket.KeepAliveOption, 1)
        self.__socket.setSocketOption(QAbstractSocket.LowDelayOption, 1)
        self.__socket.disconnected.connect(self.__onDisconnected) 
開發者ID:SergeySatskiy,項目名稱:codimension,代碼行數:14,代碼來源:client_cdm_profile.py

示例4: __init__

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def __init__(self, socket: QtNetwork.QTcpSocket = None):
        """
        We start with an empty channels list.

        :param socket: A socket if there is one existing already.
        """
        super().__init__(socket)
        self.received.connect(self._process)
        self.channels = {} 
開發者ID:Trilarion,項目名稱:imperialism-remake,代碼行數:11,代碼來源:network.py

示例5: _new_client

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def _new_client(self, socket: QtNetwork.QTcpSocket):
        """
        A new connection (QTCPPSocket) to the server occurred. Give it an id and add some general receivers to the new
        server client (wrap the socket into a NetworkClient). Add the new server client to the internal client list.
        Not intended for outside use.

        :param socket: The socket for the new connection
        """
        # wrap into a NetworkClient
        client = ServerNetworkClient(socket)

        # give it a new id
        while True:
            # theoretically this could take forever, practically only if we have 1e6 clients already
            new_id = random.randint(0, 1e6)
            if not any([new_id == client.client_id for client in self.server_clients]):
                # not any == none
                break
        # noinspection PyUnboundLocalVariable
        client.client_id = new_id
        logger.info('new client with id {}'.format(new_id))

        # add some general channels and receivers
        # TODO the receivers should be in another module eventually
        client.connect_to_channel(constants.C.LOBBY, self._lobby_messages)
        client.connect_to_channel(constants.C.GENERAL, general_messages)

        # TODO only if localhost connection add the system channel
        client.connect_to_channel(constants.C.SYSTEM, self._system_messages)

        # chat message system, handled by a single central routine
        client.connect_to_channel(constants.C.CHAT, self._chat_system)

        # finally add to list of clients
        self.server_clients.append(client) 
開發者ID:Trilarion,項目名稱:imperialism-remake,代碼行數:37,代碼來源:server.py

示例6: _new_connection

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def _new_connection(self):
        """
        Called by the newConnection signal of the QTCPServer. Not intended for outside use.
        Zero or more new clients might be available, emit new_client signal for each of them.
        """
        logger.info('new connection on server')
        while self.tcp_server.hasPendingConnections():
            # returns a new QTcpSocket
            socket = self.tcp_server.nextPendingConnection()
            # emit signal
            self.new_client.emit(socket) 
開發者ID:Trilarion,項目名稱:imperialism-remake,代碼行數:13,代碼來源:network.py

示例7: connect

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def connect(self):
        self.socket = qtnetwork.QTcpSocket()
        # set TCP_NODELAY (disable Nagle's algorithm)
        self.socket.setSocketOption(
                qtnetwork.QAbstractSocket.LowDelayOption, True)
        self.socket.connectToHost(self.host, self.port) 
開發者ID:erdewit,項目名稱:tws_async,代碼行數:8,代碼來源:twsclientqt.py

示例8: __init__

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def __init__(self, username, recipient):
        super().__init__()
        self.username = username
        self.recipient = recipient

        self.listener = qtn.QTcpServer()
        self.listener.listen(qtn.QHostAddress.Any, self.port)
        self.listener.newConnection.connect(self.on_connection)
        self.listener.acceptError.connect(self.on_error)
        self.connections = []

        self.client_socket = qtn.QTcpSocket()
        self.client_socket.error.connect(self.on_error) 
開發者ID:PacktPublishing,項目名稱:Mastering-GUI-Programming-with-Python,代碼行數:15,代碼來源:tcp_chat.py

示例9: doConnect

# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QTcpSocket [as 別名]
def doConnect(self):
        """連接服務器"""
        self.buttonConnect.setEnabled(False)
        self._timer.stop()
        self._clearConn()
        self.browserResult.append('正在連接服務器')
        # 連接控製小車的服務器
        self._connCar = QTcpSocket(self)
        self._connCar.connected.connect(self.onConnected)  # 綁定連接成功信號
        self._connCar.disconnected.connect(self.onDisconnected)  # 綁定連接丟失信號
        self._connCar.readyRead.connect(self.onReadyRead)  # 準備讀取信號
        self._connCar.error.connect(self.onError)  # 連接錯誤信號
        self._connCar.connectToHost(self.HOST, self.PORT) 
開發者ID:PyQt5,項目名稱:PyQt,代碼行數:15,代碼來源:控製小車.py


注:本文中的PyQt5.QtNetwork.QTcpSocket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。