本文整理汇总了Python中krpc.encoder.Encoder.client_name方法的典型用法代码示例。如果您正苦于以下问题:Python Encoder.client_name方法的具体用法?Python Encoder.client_name怎么用?Python Encoder.client_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类krpc.encoder.Encoder
的用法示例。
在下文中一共展示了Encoder.client_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import client_name [as 别名]
def connect(address=DEFAULT_ADDRESS, rpc_port=DEFAULT_RPC_PORT, stream_port=DEFAULT_STREAM_PORT, name=None):
"""
Connect to a kRPC server on the specified IP address and port numbers. If
stream_port is None, does not connect to the stream server.
Optionally give the kRPC server the supplied name to identify the client (up
to 32 bytes of UTF-8 encoded text).
"""
assert rpc_port != stream_port
# Connect to RPC server
rpc_connection = Connection(address, rpc_port)
rpc_connection.connect(retries=10, timeout=0.1)
rpc_connection.send(Encoder.RPC_HELLO_MESSAGE)
rpc_connection.send(Encoder.client_name(name))
client_identifier = rpc_connection.receive(Decoder.GUID_LENGTH)
# Connect to Stream server
if stream_port is not None:
stream_connection = Connection(address, stream_port)
stream_connection.connect(retries=10, timeout=0.1)
stream_connection.send(Encoder.STREAM_HELLO_MESSAGE)
stream_connection.send(client_identifier)
ok_message = stream_connection.receive(Decoder.OK_LENGTH)
assert ok_message == Decoder.OK_MESSAGE
else:
stream_connection = None
return Client(rpc_connection, stream_connection)
示例2: test_empty_client_name
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import client_name [as 别名]
def test_empty_client_name(self):
message = Encoder.client_name()
self.assertEqual (32, len(message))
self.assertEqual ('00'*32, hexlify(message))
示例3: test_long_client_name
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import client_name [as 别名]
def test_long_client_name(self):
message = Encoder.client_name('a'*33)
self.assertEqual (32, len(message))
self.assertEqual ('61'*32, hexlify(message))
示例4: test_client_name
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import client_name [as 别名]
def test_client_name(self):
message = Encoder.client_name('foo')
self.assertEqual (32, len(message))
self.assertEqual ('666f6f'+'00'*29, hexlify(message))