本文整理匯總了Python中xdrlib.Unpacker.unpack_float方法的典型用法代碼示例。如果您正苦於以下問題:Python Unpacker.unpack_float方法的具體用法?Python Unpacker.unpack_float怎麽用?Python Unpacker.unpack_float使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xdrlib.Unpacker
的用法示例。
在下文中一共展示了Unpacker.unpack_float方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_float [as 別名]
def run(self):
while self.server_running:
potential_read = [self.server_socket]
if self.client is not None:
potential_read.append(self.client)
try:
ready_to_read, ready_to_write, in_erro = select.select(
potential_read, [], [])
if self.server_socket in ready_to_read:
conn, addr = self.server_socket.accept()
self.client = conn
print('New connection from ', addr)
elif self.client in ready_to_read:
# self.client.recv_into(self.buffer, 512)
recv = self.client.recv(128)
self.buffer += recv
if len(recv) == 0:
print('Disconnection from client')
self.client.close()
self.client = None
self.buffer = ''
continue
unpack = Unpacker(self.buffer)
if len(self.buffer) >= unpack.unpack_int():
unpack.set_position(0)
size = unpack.unpack_int()
cmd = unpack.unpack_int()
if cmd == ServerMouseController.PACKET_MOVE:
# Mouse move control
x = unpack.unpack_float()
y = unpack.unpack_float()
print(size, cmd, x, y)
self.mouse_controller.move(
self.mouse_controller.position()[0] - x,
self.mouse_controller.position()[1] - y)
elif cmd == ServerMouseController.PACKET_CLICK:
# Mouse click control
button = unpack.unpack_int()
nb_click = unpack.unpack_int()
print(size, cmd, button, nb_click)
self.mouse_controller.click(
self.mouse_controller.position()[0],
self.mouse_controller.position()[1],
button,
nb_click)
elif cmd == ServerMouseController.PACKET_SCROLL:
# Mouse scrolling
x = unpack.unpack_float()
y = unpack.unpack_float()
print(size, cmd, x, y)
self.mouse_controller.scroll(
vertical=int(y), horizontal=int(x))
self.buffer = self.buffer[unpack.get_position():]
except select.error as e:
print(e)
if self.client is not None:
self.client.close()
self.server_socket.close()
print('Server stop')