Hi there,
I faced a problem with FileTransfer on mobile internet connections. I am able to send a file without problems over wifi but I can´t send the file over full and stable mobile connection. The transfer status allways shows -1 and seem to loop forever. Also, receiving usual messages is not possible anymore, but sending works. There is no exception thrown, wether at the file transfer nor on sending/receiving usual messages. So I guess the file transfer is blocking something and maybe destroys the connection. But by testing, connection and authentication are ok.
I tried it with both methods, sendStream() and sendFile(), both methods have the same behaviour. I do this stuff in an AsyncTask() in doInBackground().
Here my part of code:
@Override
protected Void doInBackground(Void… params) {
mOutgoingFileTransfer = mFileTransferManager.createOutgoingFileTransfer(toUserJid);
File file = new File(filePath);
String fileName = file.getName();
//also tried with sendStream(), same behaviour
// byte[] sdataToSend = FileUtils.FileToByte(file);
// mOutgoingFileTransfer.sendStream(new ByteArrayInputStream(dataToSend), fileName, dataToSend.length, subject + “, I sent the file:” + fileName);
try {
Log.d(“TEST”, “SEND FILE”);
mOutgoingFileTransfer.sendFile(file, “TEST”);
} catch (SmackException e) {
Log.d(“TEST”, " SEND FILE ERROR:" + e);
e.printStackTrace();
}
streamId = mOutgoingFileTransfer.getStreamID();
while (!mOutgoingFileTransfer.isDone()) {
switch (mOutgoingFileTransfer.getStatus()) {
case error:
Log.d(“TEST”, “OUTGOING FILE ERROR:” + mOutgoingFileTransfer.getError());
break;
default:
//allways get -1 at mobile connection. On wifi it shows the bytes that are sent
Log.d(“TEST”, “OUTGOING FILE” + " bytes:" + mOutgoingFileTransfer.getBytesSent());
break;
}
return null;
}
}.execute();
My question is:
-
why is File Transfer blocking the receiving of usual messages?
-
Is it because of the wrong port? I send the fileTransfer over the default port 5222 (or any that is used by the server) and it works without problem on wifi connection.
-
If the port is the problem, so how to switch between ports (normal port 5222 and transfer port 7777)while user is connected?
For information: Sending files and sending/receiving messages are implemented separated, they just use the same XMPPTCPConnection. They use different tasks while messages are send over the connection with sendStanza(), Files are send via the FileTransferManager with OutgoingFileTransfer.
Is there anyone who has an idea about that?
many thanks for some suggestions…
EDIT
Turned out that outgoingFileTransfer.isDone() is never comes up, so the while loop consumes every resource and the messages could not be received. BUT the problem still is there, on mobile connection, no file transfer. There is a 0KB sized file on the receiver side, so anything is trying to come in, but does not work.
Nachricht geändert durch Stefan hennemann