Sending Iq messages

Steffen Vogel edited this page Sep 7, 2015 · 4 revisions

Sending an Iq message always involves receiving an immediate response from server. The only way to determine that a specific iq response is associated to a specific iq we previously sent is through its id attribute.

An iq response always carries the same id as the iq request we initially sent, therefore some kind of mapping between received responses and sent iq requests must be done. This is done in YowProtocolLayers by using the method "_sendIq" for sending Iqs. The method accepts as parameters the IqProtocolEntity to send, an optional success callback for when receiving iq response of type "result", and an optional error callback for when receiving iq response of type "error"


class GroupsLayer(YowProtocolLayer):
    def getMyGroups(self):
        self._sendIq(ListGroupsIqProtocolEntity(), self.onGroupsResult, self.onGroupsError)
    def onGroupsResult(self, protocolTreeNode, listGroupsIqProtocolEntity):

    def onGroupsError(self, protocolTreeNode, listGroupsIqProtocolEntity):

The same method also is available to YowInterfaceLayer with a slight variation. The callbacks get an actual ProtocolEntity instance instead of ProtocolTreeNode instance, due to the fact that a YowInterfaceLayer is placed on top of YowProtocolLayers which carry the translation of ProtocolTreeNode to ProtocolEntity.

class GroupsInterfaceLayer(YowInterfaceLayer):
    def createGroup(self, subject):
        self._sendIq(CreateGroupsIqProtocolEntity(subject), self.onGroupCreateResult, self.onGroupCreateError)
    def onGroupCreateResult(self, successCreateGroupsIqProtocolEntity, createGroupsIqProtocolEntity):

    def onGroupCreateError(self, errorIqProtocolEntity, createGroupsIqProtocolEntity):
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.