本文整理汇总了Python中packet.Packet.read_from_socket方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.read_from_socket方法的具体用法?Python Packet.read_from_socket怎么用?Python Packet.read_from_socket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.read_from_socket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_packet
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import read_from_socket [as 别名]
def read_packet(self):
type = struct.unpack("i", self._readn(4))[0]
if type == CONTENT_TYPES["packet_data"]:
packet_len = struct.unpack("i", self._readn(4))[0]
packet = Packet.read_from_socket(self, packet_len, decrypt_func=self.crypto.decrypt)
print "read from net %s" % packet
return packet
elif type == CONTENT_TYPES["update_session"]:
self.update_session_key()
return self.read_packet()
示例2: serve_once
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import read_from_socket [as 别名]
def serve_once(self, poll_interval = 0):
processed = False
#logging.debug('listening on socket fileno: %s' %(self.listen_sockets))
try:
r, w, e = select.select(self.listen_sockets, [], [], poll_interval)
#logging.debug('readable socket fileno: %s' %(r))
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
logging.debug("I/O error({0}): {1}".format(e.errno, e.strerror))
raise
except (OSError, select.error) as e:
if e.args[0] != errno.EINTR:
raise
for sock in r:
#read socket into Packet
#pop Packet onto Queue
logging.debug('reading in socket')
processed = True
p = Packet()
p.read_from_socket(sock)
p.recv_time = time.time()
self.raw_in_queue.put(p)
return processed