service-unavailable 503 error for file transfer in XMPP with iOS
Asked Answered
D

4

1

I am using XMPP with iOS for file transfer.

I am using following lines of code to send file. But I am continuously getting single error and stuck on issue.

<error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error>

I have used following code in app to send file between two devices.

XMPPJID *jid = self.chatUserJID;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
                  @"aqua.png" ];
UIImage* image = [UIImage imageWithContentsOfFile:path];

XMPPSIFileTransfer *sifiletransfer=[[XMPPSIFileTransfer alloc]init];

[sifiletransfer initiateFileTransferTo:jid withData:UIImagePNGRepresentation(image)];
sifiletransfer.sid = [[self xmppStream] generateUUID];

if ([jid.domain isEqualToString:[self.xmppStream myJID].domain]) {
    [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain, nil]];
} else {
    [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain,[self.xmppStream myJID].domain, nil]];
}
TURNSocket *socket = [[TURNSocket alloc] initWithStream:[[self appDelegate] xmppStream] toJID:jid];;
[socket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];

Log for file transfer is shown as below.

SEND:

<iq type="get" to="192.168.2.120" id="596BC614-8653-43CC-925B-E56CFF6DB8CF"><query xmlns="http://jabber.org/protocol/disco#items"/></iq>

RECV:

<iq xmlns="jabber:client" type="result" id="596BC614-8653-43CC-925B-E56CFF6DB8CF" from="192.168.2.120" to="[email protected]/4a0ce4e9"><query xmlns="http://jabber.org/protocol/disco#items"><item jid="conference.192.168.2.120" name="Public Chatrooms"/><item jid="pubsub.192.168.2.120" name="Publish-Subscribe service"/><item jid="proxy.192.168.2.120" name="Socks 5 Bytestreams Proxy"/></query></iq>

SEND:

<iq type="get" to="proxy.192.168.2.120" id="03078D21-008A-444C-87D4-FCC370D16E5D"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>

RECV:

<iq xmlns="jabber:client" type="result" id="03078D21-008A-444C-87D4-FCC370D16E5D" from="proxy.192.168.2.120" to="[email protected]/4a0ce4e9"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="proxy" name="SOCKS5 Bytestreams Service" type="bytestreams"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>

SEND:

<iq type="get" to="proxy.192.168.2.120" id="C537E4CC-AD48-4517-85D7-96D6DF1658F4"><query xmlns="http://jabber.org/protocol/bytestreams"/></iq>

RECV:

<iq xmlns="jabber:client" type="result" id="C537E4CC-AD48-4517-85D7-96D6DF1658F4" from="proxy.192.168.2.120" to="[email protected]/4a0ce4e9"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost jid="proxy.192.168.2.120" host="192.168.2.120" port="7777"/></query></iq>

SEND:

<iq type="set" to="[email protected]" id="A791E4C0-3235-402F-A537-94FB296BA0C4"><query xmlns="http://jabber.org/protocol/bytestreams" sid="A791E4C0-3235-402F-A537-94FB296BA0C4" mode="tcp"><streamhost xmlns="http://jabber.org/protocol/bytestreams" jid="proxy.192.168.2.120" host="192.168.2.120" port="7777"/></query></iq>

RECV:

<iq xmlns="jabber:client" type="error" id="A791E4C0-3235-402F-A537-94FB296BA0C4" from="[email protected]" to="[email protected]/4a0ce4e9"><query xmlns="http://jabber.org/protocol/bytestreams" sid="A791E4C0-3235-402F-A537-94FB296BA0C4" mode="tcp"><streamhost jid="proxy.192.168.2.120" host="192.168.2.120" port="7777"/></query><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

Can any body please suggest me what can be the mistake because of which this issue is taking place?

I have done following configuration to enable file transfer.

Enabled file transfer from Openfire. Server -> Server Settings -> File Transfer Settings -> Enable on port number 7777

Set following server properties in Openfire.

xmpp.domain             192.168.2.120
xmpp.proxy.enabled      true
xmpp.proxy.externalip   192.168.2.120 / proxy.192.168.2.120 // Tried both
xmpp.proxy.port         7777

I request you to help if you have any idea.

Thanks in advance!!!

Dennison answered 8/10, 2014 at 6:33 Comment(1)
Hey Man! looks like you haven't passing correct JID with resource.A complete JID with resource looks like [email protected]/4a0ce4e9.Masha
M
2

looks like you haven't passing correct JID with resource. A complete JID with resource looks like [email protected]/4a0ce4e9. Last special "4a0ce4e9" are resource which should be in both JID to and from.

You should have

from="[email protected]/someResourceId"

to="[email protected]/4a0ce4e9

Masha answered 8/10, 2014 at 13:51 Comment(7)
I have tried using full resource id in from and to also but still there are some issue and showing same error.Dennison
I have uploaded latest code on following link can you please check it out? goo.gl/h5x675 If we can solve the problemDennison
Okay.Buddy let me check that.Masha
Hey!Jayesh I sending you my app delegate.i have modified app delegate according to my use to transfer image.I have merged XMPPSIFiletranfer all methods in my app delegate. Just pass data in follwing mathod -(void)sendToOtherDevice:(NSData )fileData receiverJid:(NSString *)receiverJid file:(NSString *)fileName and handle delegate methods of XMPPSiFiletranfer in appdelegate file.ie - (void)receivedImage:(NSData)image from:(XMPPJID*)from{Masha
Get appDelegates file from here dropbox.com/s/t0lyml945qclw76/Archive%202.zip?dl=0Masha
What I have found difference is in Turn Socket Class. In my TurnSocket method is - (id)initWithStream:(XMPPStream )stream toJID:(XMPPJID *)aJid where as in your class method is as followed. - (id)initWithStream:(XMPPStream *)stream toJID:(XMPPJID *)aJid sid:(NSString)sId. So can you share TurnSocket class?Dennison
Let us continue this discussion in chat.Dennison
R
1

You can use file transfer extension for sending file. You can refer XMPP File Transfer Demo on GitHub. There is also sample application for file transfer using it.

Ruby answered 6/11, 2014 at 12:21 Comment(0)
M
0

I had same problem, I investigated the stanza and solved it this way.

Many people use "/Smack" or "/Resource" as resource part in jid, that is not wrong but you can set resource another way.

Like Arpan Dixit explained, resource path is changing with every presence changed of user. Lets say we want to send image to this user: "user1@mydomain"

You must add "/Resource" part to this jid and it become this: user1@mydomain/Resource

But /Resource path is changing with presence so you must follow every presence change to update resource path. Best way is to get user presence is in roster listener and in presencheChanged() method you get last user resource part like this:

Roster roster=getRoster();
roster.addRosterListener(new RosterListener() {
                @Override
                public void entriesAdded(Collection<Jid> addresses) {
                    Log.d("entriesAdded", "ug");
                    context.sendBroadcast(new Intent("ENTRIES_ADDED"));
                }

                @Override
                public void entriesUpdated(Collection<Jid> addresses) {
                    Log.d("entriesUpdated", "ug");
                }

                @Override
                public void entriesDeleted(Collection<Jid> addresses) {
                    Log.d("entriesDeleted", "ug");
                }

                @Override
                public void presenceChanged(Presence presence) {
                    Log.d("presenceChanged", "ug");
                    //Resource from presence
                    String resource = presence.getFrom().getResourceOrEmpty().toString();
                    //Update resource part for user in DB or preferences
                    //...
                }
            });
}

Resource string will be some generated string like "6u1613j3kv" and jid will become:

user1@mydomain/6u1613j3kv

That means that you must create your outgoing transfer like this:

EntityFullJid jid = JidCreate.entityFullFrom("user1@mydomain/6u1613j3kv"); 
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(jid)
transfer.sendFile(new File("DirectoryPath"), "Description");

Ofcourse this code is example from Android but it is same for your application on iOS.

Also this can be configured the easy way, just set the resource on

XMPPTCPConnectionConfiguration.Builder //android example.

like

XMPPTCPConnectionConfiguration.Builder configurationBuilder = 
XMPPTCPConnectionConfiguration.builder(); 

configurationBuilder.setResource("yourResourceName");
Midships answered 15/2, 2018 at 21:23 Comment(0)
V
0

My program worked fine at first, and the same problem occured later. My problem is that the offline message capacity exceeds the preset value in my openfire server. I check my openfire server,and in "Server Settings" I find an item called "offline messaging policy",I expanded the offline message storage capacity of single user. Then the app works fine.

Verlaverlee answered 20/8, 2018 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.