本文整理汇总了Python中Lib.pack16bit方法的典型用法代码示例。如果您正苦于以下问题:Python Lib.pack16bit方法的具体用法?Python Lib.pack16bit怎么用?Python Lib.pack16bit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lib
的用法示例。
在下文中一共展示了Lib.pack16bit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendTCPRequest
# 需要导入模块: import Lib [as 别名]
# 或者: from Lib import pack16bit [as 别名]
def sendTCPRequest(self, server):
" do the work of sending a TCP request "
first_socket_error = None
self.response=None
for self.ns in server:
#print "trying tcp",self.ns
try:
if self.ns.count(':'):
if hasattr(socket,'has_ipv6') and socket.has_ipv6:
self.socketInit(socket.AF_INET6, socket.SOCK_STREAM)
else: continue
else:
self.socketInit(socket.AF_INET, socket.SOCK_STREAM)
try:
# TODO. Handle timeouts &c correctly (RFC)
self.time_start=time.time()
self.conn()
buf = Lib.pack16bit(len(self.request))+self.request
# Keep server from making sendall hang
self.s.setblocking(0)
# FIXME: throws WOULDBLOCK if request too large to fit in
# system buffer
self.s.sendall(buf)
# SHUT_WR breaks blocking IO with google DNS (8.8.8.8)
#self.s.shutdown(socket.SHUT_WR)
r=self.processTCPReply()
if r.header['id'] == self.tid:
self.response = r
break
finally:
self.s.close()
except socket.error, e:
first_socket_error = first_socket_error or e
continue
示例2: sendTCPRequest
# 需要导入模块: import Lib [as 别名]
# 或者: from Lib import pack16bit [as 别名]
def sendTCPRequest(self, server):
" do the work of sending a TCP request "
self.response=None
for self.ns in server:
try:
self.socketInit(socktype_from_addr(self.ns), socket.SOCK_STREAM)
self.time_start=time.time()
self.conn()
self.s.send(Lib.pack16bit(len(self.request))+self.request)
self.s.shutdown(1)
self.response=self.processTCPReply()
except socket.error:
continue
break
if not self.response:
raise DNSError,'no working nameservers found'