本文整理汇总了Python中PyQt5.QtNetwork.QLocalSocket.setServerName方法的典型用法代码示例。如果您正苦于以下问题:Python QLocalSocket.setServerName方法的具体用法?Python QLocalSocket.setServerName怎么用?Python QLocalSocket.setServerName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtNetwork.QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket.setServerName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import setServerName [as 别名]
class Client:
def __init__(self):
self.socket = QLocalSocket()
self.socket.setServerName(piony.G_SOCKET_NAME)
self.socket.error.connect(self.displayError)
self.socket.disconnected.connect(self.socket.deleteLater)
def _log_(self, text, *args):
logger.info(self.__class__.__qualname__ + ': ' + text, *args)
def connect(self):
self.socket.abort()
self._log_("connection attempt")
self.socket.connectToServer()
def send(self, argv):
data = QByteArray()
out = QDataStream(data, QIODevice.WriteOnly)
out.setVersion(QDataStream.Qt_5_0)
out.writeQVariant(argv)
self._log_("writes: %s", str(data))
self.socket.write(data)
self.socket.flush()
self.socket.disconnectFromServer()
def displayError(self, err):
msg = {
QLocalSocket.ServerNotFoundError:
"The host was not found. Check the host name and port.",
QLocalSocket.ConnectionRefusedError:
"The connection was refused by the peer. "
"Check server is running, it's host and port.",
QLocalSocket.PeerClosedError:
"Peer was closed", # None,
}.get(err, "Client error: {}.".format(self.socket.errorString()))
self._log_(msg)