File Transfer from a client behind a Nat

Hi everyone!!

I am using Smack to create a very simple client. I have no problems when using IM, but the problem comes when I try to receive a file from a client like PSI behind a NAT. When Smack tries to create a connection to receive the file, it is using the private IP of the PSI client instead of the public IP of the router, so the transfer never works. Why is Smack doing this?

I would really appreciate your help.


Just adding some info: when using Empathy and trying to send a file to my client it says: “contact doesn’t have file transfer capabilities”.

Message was edited by: Solaiemes. Wrong Direction of Transfer…

I am still stucked with this problem. I’ve been investigating how different XMPP clients work. When sending a file between two PSI clients I’ve seen that not only the file sender sends its IP to the receiver but also does the receiver to the sender. Is this allowed?? Why does not smack do this??


Smack 3.2. has changed the file transfer procedures quite a bit. There are basiacally three options for file transfer

  1. Bytestream

  2. IBB with message stanzas

  3. IBB with IQ stanzas

Smack 3.2 uses 1) and 3). Smack 3.1 uses 1) and 2) Depending on the capabilities of your client, you may run in a problem using IBB. This is the fall back transfer mode, if bytestream is not working.

Thanks for your answer!

The point is that even when IBB is supported, it is never used when bytestreams fails.

This is what happened after a failure:


<iqid="purpleaf9d229b"to=""from=“” type=“error”>

<query xmlns=""sid=“purpleaf9d229a” mode=“tcp”>

<streamhost jid=""host=“” port=“34926”/>

<streamhost jid=""host=“” port=“7777”/>

<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"xml:lang=“en”>Could not establish socket with anyprovided host


<iqid="purpleaf9d229c"to=""from=“” type=“set”>

<open xmlns=""block-size=“4096” sid="purpleaf9d229a"stanza=“iq”/>

The first message is what my Smack client sent after a bytestreams failure, and the second message is what I received from Pidgin as an answer. Smack just ignored this message.

Appart from this I don’t know whether I am right or wrong about how bytestreams works when using a proxy like When you are using this kind of transmission, do both sides of the transmission need to open a connection to the proxy, don’t they? In that case, I always see Smack trying to open the connection but the other side never does… How does the other participant know that the connection to the proxy has to be opened??

Thanks in advance!!

Hi Solaiemes,

can you please post the disco#info and disco#items messages for me?


This is the sequence:

Rcvd by Smack:

<iqid="purpleaf9d2298"to=""from=“” type=“get”>


<iqid="purpleaf9d2298"to="" type=“result”>

<identity category=“client” name="Smack"type=“pc”/>


This is all I have about disco#info (there is no disco#items) for this case, that is receiving a file from Pidgin in my own client.

I have added a STUN server in Pidgin. As a result IBB now is possible. Now it is trying to establish a connection with both, the public router address (given by the STUN server) and the private computer address, and as it fails IBB occurs.

If I remove the STUN server and no proxy is configured, both IBB and bytestreams fail. What I have seen in Wireshark is that my computer (with public IP) is trying to connect to the private IP address,, where Pidgin is installed, once and again. I know this is quite weird but is what I have seen.

To receive a file using bytestreams, which ports need to be opened in my router??

By the way, if you try to send disco#items to, what you receive is 501, feature-not-implemented, and file transfer won’t happen.


Ok, my fault!!!

If you want to use bytestreams behind nat just try to find a proxy server that works. It was always trying to use but never worked. It could connect to it but then things went wrong.

When sending a file to a gmail account from Smack, disco#items answer is 501, so I decided to change this query to everytime I see a disco#items addressed to

For Pidgin to work using IBB, I configured its STUN server. Even when I know this wont work for bytestreams I don’t know the reason but the fact is that when bytestreams fails IBB occurs… If I just send my private IP to Smack it won’t work.

I hope this will help you. Of course there are some problems to correct but at least it seems to work fine now.