本文整理汇总了Python中frame.Frame.receive_frame方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.receive_frame方法的具体用法?Python Frame.receive_frame怎么用?Python Frame.receive_frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frame.Frame
的用法示例。
在下文中一共展示了Frame.receive_frame方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Stomp
# 需要导入模块: from frame import Frame [as 别名]
# 或者: from frame.Frame import receive_frame [as 别名]
class Stomp(object):
'''
classdocs
'''
def __init__(self, serveraddr='172.18.15.26', port = 61613):
'''
Constructor
'''
self.serveraddr = serveraddr
self.serverport = port
self.servername = 'apachemq'
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.isconnected = False
self.issubscribed = None
self.accept_version = '1.1'
self.subscribe_destination = '/queue/stomp'
self.ack = 'auto'
self.frame = Frame(self.sock)
def connect_server(self, username=None, passcode=None):
'''
connect to stomp server
'''
self.frame.framecmd = None
self.frame.frameheader = {}
self.frame.framebody = None
try:
self.sock.connect((self.serveraddr, self.serverport))
except ConnectionRefusedError:
print("socket timeout")
self.isconnected = False
return self.isconnected
headers = {}#????
if username and passcode:
self.frame.frameheader.update({'login':username, 'passcode':passcode})
self.frame.frameheader.update({'accept-version':self.accept_version,})
self.frame = self.frame.build_frame({'command':'CONNECT',\
'header':self.frame.frameheader,\
'body':'\x00'})
self.frame.send_frame((self.frame.frame_to_string()).encode("utf-8"))
self.frame.receive_frame()
self.isconnected = True
#print ("Connect activemq:")
#print (self.frame.frameheader)
return self.isconnected
def dis_connect_server(self):
self.frame.framecmd = None
self.frame.frameheader = {}
self.frame.framebody = None
if self.issubscribed:
self.unsubscribe()
self.frame = self.frame.build_frame({'command':'DISCONNECT',\
'header':self.frame.frameheader,\
'body':'\x00'})
self.frame.send_frame((self.frame.frame_to_string()).encode("utf-8"))
self.sock.close()
self.isconnected = False
def send(self, destination="/queue/stomp", body="", content_type="text/plain", receipt=None):
'''
if the send frame has a receipt header, the server must reply a RECEIPT frame after successfuly deal with it.
'''
self.frame.framecmd = None
self.frame.frameheader = {}
self.frame.framebody = None
self.frame.frameheader.update({'destination':destination, 'content-type':content_type})
if receipt:
self.frame.frameheader.update({'receipt':receipt})
self.frame.frameheader.update({'content-length':len(body)})
self.frame = self.frame.build_frame({'command':'SEND',\
'header':self.frame.frameheader,\
'body':body+'\x00'})
self.frame.send_frame((self.frame.frame_to_string()).encode("utf-8"))
def receive(self):
self.frame.receive_frame()
def subscribe(self, id='0', destination="/queue/stomp", ack="auto"):
self.frame.framecmd = None
self.frame.frameheader = {}
self.frame.framebody = None
self.subscribe_destination = destination
self.ack = ack
self.frame.frameheader.update({'id':id})
self.frame.frameheader.update({'destination':self.subscribe_destination, 'ack':self.ack})
self.frame = self.frame.build_frame({'command':'SUBSCRIBE',\
'header':self.frame.frameheader,\
'body':'\x00'})
self.frame.send_frame((self.frame.frame_to_string()).encode("utf-8"))
self.issubscribed = True
def unsubscribe(self, id='0'):
self.frame.framecmd = None
self.frame.frameheader = {}
self.frame.framebody = None
self.frame.frameheader.update({'id':id})
self.frame = self.frame.build_frame({'command':'UNSUBSCRIBE',\
#.........这里部分代码省略.........