本文整理匯總了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))