powered by Jive Software

Asmack android file trasfer problem

Hi, I’m trying to setup a basic test sample of file transfer useing SIP XEP-0096 XMPP extension.

for may test case I run openfire on CentOS6.4-64Bit Virtual Box. iptables is off.

Storage solution is based on DB (mysql).

It seems that receiver doesn’t negotiates well with the sender, Could you please have a look at logcats and my sample code(Attached)?

Sender LogCat Main Part:

avatar1.pnghttp://jabber.org/protocol/bytestreamshttp://jabber.org/protocol/ibb

Receiver LogCat:

03-04 20:00:12.638: I/System.out(11605): ??:??:?? بعدازظهر RCV (1319091388): avatar1.pnghttp://jabber.org/protocol/bytestreamshttp://jabber.org/protocol/ibb

I’m working on a customized version of Xabber Client (https://github.com/redsolution/xabber-android/).

Please look at Provider method invokatins in OnCreate Activity if I missed something.

I define a FileTransferLister acccording to a tutorial from the link bellowm if I didn’t miss any part.:

http://harryjoy.com/2012/08/18/file-transfer-in-android-with-asmack-and-openfire /

Any help or idea would be appreciated

I aim to put a step by step guid as a document in this forum, maybe usefull for feautures.

Best Regards

Vahid

Thanks a lot.
logcat-sender.log.zip (1137 Bytes)
logcat-receiver.log.zip (613 Bytes)
test-panel.java.zip (4060 Bytes)

I Triied again and put change FileTransferLister to code bellow, but no Log was outputed, it seems Listener is

not even invoke when a file-transfer query received!

public void fileTransferListener()

{

FileTransferManager manager = new FileTransferManager(connection);

manager.addFileTransferListener(new FileTransferListener() {

@Override

public void fileTransferRequest(FileTransferRequest request)

{

Log.i(“FILE TRANSFER Listener”,“New File Recived”); //this part is not exected!!!

}

});

}

Finally Sender get this error:

03-04 21:26:29.518: I/FILE TRANSFER(12121): refused cancelled error The remote user did not respond or the connection timed out.

what other info do you need for better inspection and resolving issue?

Thanks for your kind support

After some and debug, I reach final solution for file trasfer just worked as expected :wink:

This is the solution worked for me:

1- make connection configuration:

public void setConnectionConfig(View view)

{

EditText editText = (EditText) findViewById(R.id.led_server_address);

HOST = editText.getText().toString();

SERVICE=HOST;

if(HOST.equals(""))

{

showMessage(“invalid HOST”);

return;

}

XMPPConnection.DEBUG_ENABLED = true;

connConfig = new AndroidConnectionConfiguration(HOST, PORT, SERVICE);

Log.i(“onCreate”,“Creating Connection Configuration DONE :-).”);

showMessage(“Creating Connection Configuration DONE :-).”);

connection = new XMPPConnection(connConfig);

Log.i(“makeConnection”, “XMPP Connection Created”);

showMessage(“Connection Created”);

}

2- Make Connection:

//Create Connection to XMPP Server

public void makeConnection(View view)

{

if(connection==null)

{

Log.e(“makeConnection”, “first configure connection”);

//showMessage(“first configure connection”);

return;

}

new Thread( new Runnable()

{

@Override

public void run() {

// TODO Auto-generated method stub

if(connection.isConnected())

{

Log.e(“makeConnection”, "Already Connected to "+ connection.getHost());

//showMessage("Already Connected to "+ connection.getHost());

return ;

}

//connection already initialized outside

try {

Log.i(“makeConnection”, “Try Make connection”);

//showMessage("Try Make connection to "+ connection.getHost());

connection.connect();

if(connection!=null && connection.isConnected())

{

Log.i(“makeConnection”,“Connection Established! :-)”);

//showMessage("Connection Established to "+ connection.getHost());

}

} catch (XMPPException ex) {

Log.e(“makeConnection”, "Failed to connect to "+ connection.getHost());

//showMessage("Failed to connect to "+ connection.getHost());

Log.e(“makeConnection”, ex.toString());

}

return;

}

}

).start();

}

3- Login to Server:

//Login to XMPP Server

public void loginAccount(View view)

{

if(connection==null || !connection.isConnected())

{

Log.e(“loginAccount”, " first try connect to Server: "+ HOST);

showMessage("First try connect to Server: "+HOST);

return;

}

/*

else if(!connection.getUser().equals(""))

{

Log.e(“loginAccount”, " already connected as : "+ connection.getUser());

showMessage( " already connected as : "+ connection.getUser());

return;

}*/

EditText editText = (EditText) findViewById(R.id.led_username);

USERNAME = editText.getText().toString();

USERNAME+="@"+HOST;

editText = (EditText) findViewById(R.id.led_passwd);

PASSWORD = editText.getText().toString();

try {

connection.login(USERNAME,PASSWORD,“GapoGopFileTransfer”);

showMessage("Logined As “+USERNAME+” to "+connection.getHost());

Log.i(“loginAccount”, "Logined As “+USERNAME+” to "+connection.getHost());

configure(ProviderManager.getInstance());

startListener(view);

} catch (XMPPException ex) {

Log.e(“loginAccount”, "Failed to login to "+ connection.getHost());

Log.e(“loginAccount”, ex.toString());

retry_times++;

if(retry_times>MAX_RETRY)

{

Log.e(“loginAccount”, "max retries reached to connect "+ connection.getHost());

showMessage("Failed to login to "+connection.getHost());

retry_times=0;

}

else

loginAccount(view);

}

}

4- Here are 2 Assistant Methods I use:

public void configure(ProviderManager pm) {

// Private Data Storage

pm.addIQProvider(“query”, “jabber:iq:private”,

new PrivateDataManager.PrivateDataIQProvider());

// Time

try {

pm.addIQProvider(“query”, “jabber:iq:time”,

Class.forName(“org.jivesoftware.smackx.packet.Time”));

} catch (ClassNotFoundException e) {

Log.w(“TestClient”,

“Can’t load class for org.jivesoftware.smackx.packet.Time”);

}

// Roster Exchange

pm.addExtensionProvider(“x”, “jabber:x:roster”,

new RosterExchangeProvider());

// Message Events

pm.addExtensionProvider(“x”, “jabber:x:event”,

new MessageEventProvider());

// Chat State

pm.addExtensionProvider(“active”,

            "[http://jabber.org/protocol/chatstates](http://jabber.org/protocol/chatstates)",

new ChatStateExtension.Provider());

pm.addExtensionProvider(“composing”,

            "[http://jabber.org/protocol/chatstates](http://jabber.org/protocol/chatstates)",

new ChatStateExtension.Provider());

pm.addExtensionProvider(“paused”,

            "[http://jabber.org/protocol/chatstates](http://jabber.org/protocol/chatstates)",

new ChatStateExtension.Provider());

pm.addExtensionProvider(“inactive”,

            "[http://jabber.org/protocol/chatstates](http://jabber.org/protocol/chatstates)",

new ChatStateExtension.Provider());

pm.addExtensionProvider(“gone”,

            "[http://jabber.org/protocol/chatstates](http://jabber.org/protocol/chatstates)",

new ChatStateExtension.Provider());

// XHTML

    pm.addExtensionProvider("html", "[http://jabber.org/protocol/xhtml-im](http://jabber.org/protocol/xhtml-im)",

new XHTMLExtensionProvider());

// Group Chat Invitations

pm.addExtensionProvider(“x”, “jabber:x:conference”,

new GroupChatInvitation.Provider());

// Service Discovery # Items

    pm.addIQProvider("query", "[http://jabber.org/protocol/disco#items](http://jabber.org/protocol/disco#items)",

new DiscoverItemsProvider());

// Service Discovery # Info

    pm.addIQProvider("query", "[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)",

new DiscoverInfoProvider());

// Data Forms

pm.addExtensionProvider(“x”, “jabber:x:data”, new DataFormProvider());

// MUC User

    pm.addExtensionProvider("x", "[http://jabber.org/protocol/muc#user](http://jabber.org/protocol/muc#user)",

new MUCUserProvider());

// MUC Admin

    pm.addIQProvider("query", "[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)",

new MUCAdminProvider());

// MUC Owner

    pm.addIQProvider("query", "[http://jabber.org/protocol/muc#owner](http://jabber.org/protocol/muc#owner)",

new MUCOwnerProvider());

// Delayed Delivery

pm.addExtensionProvider(“x”, “jabber:x:delay”,

new DelayInformationProvider());

// Version

try {

pm.addIQProvider(“query”, “jabber:iq:version”,

Class.forName(“org.jivesoftware.smackx.packet.Version”));

} catch (ClassNotFoundException e) {

// Not sure what’s happening here.

}

// VCard

pm.addIQProvider(“vCard”, “vcard-temp”, new VCardProvider());

// Offline Message Requests

    pm.addIQProvider("offline", "[http://jabber.org/protocol/offline](http://jabber.org/protocol/offline)",

new OfflineMessageRequest.Provider());

// Offline Message Indicator

pm.addExtensionProvider(“offline”,

            "[http://jabber.org/protocol/offline](http://jabber.org/protocol/offline)",

new OfflineMessageInfo.Provider());

// Last Activity

pm.addIQProvider(“query”, “jabber:iq:last”, new LastActivity.Provider());

// User Search

pm.addIQProvider(“query”, “jabber:iq:search”, new UserSearch.Provider());

// SharedGroupsInfo

pm.addIQProvider(“sharedgroup”,

            "[http://www.jivesoftware.org/protocol/sharedgroup](http://www.jivesoftware.org/protocol/sharedgroup)",

new SharedGroupsInfo.Provider());

// JEP-33: Extended Stanza Addressing

pm.addExtensionProvider(“addresses”,

            "[http://jabber.org/protocol/address](http://jabber.org/protocol/address)",

new MultipleAddressesProvider());

// FileTransfer

    pm.addIQProvider("si", "[http://jabber.org/protocol/si](http://jabber.org/protocol/si)",

new StreamInitiationProvider());

    pm.addIQProvider("query", "[http://jabber.org/protocol/bytestreams](http://jabber.org/protocol/bytestreams)",

new BytestreamsProvider());

// Privacy

pm.addIQProvider(“query”, “jabber:iq:privacy”, new PrivacyProvider());

    pm.addIQProvider("command", "[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",

new AdHocCommandDataProvider());

pm.addExtensionProvider(“malformed-action”,

            "[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",

new AdHocCommandDataProvider.MalformedActionError());

pm.addExtensionProvider(“bad-locale”,

            "[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",

new AdHocCommandDataProvider.BadLocaleError());

pm.addExtensionProvider(“bad-payload”,

            "[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",

new AdHocCommandDataProvider.BadPayloadError());

pm.addExtensionProvider(“bad-sessionid”,

            "[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",

new AdHocCommandDataProvider.BadSessionIDError());

pm.addExtensionProvider(“session-expired”,

            "[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",

new AdHocCommandDataProvider.SessionExpiredError());

}

void startListener(final View view)

{

FileTransferManager manager = new FileTransferManager(connection);

final Intent resultIntent = new Intent(this, FileTransferRequestActivity.class);

final IncomingFileTransferWrapper transferWrapper = new IncomingFileTransferWrapper();

manager.addFileTransferListener(new FileTransferListener()

{

@Override

public void fileTransferRequest(final FileTransferRequest request)

{

Log.i(“FileListener”,“It Seems something is sent to me! :-O”);

final NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(getApplicationContext())

.setSmallIcon(android.R.drawable.ic_dialog_info)

.setContentTitle(“FileListener”)

.setContentText("File Transfer Request From “+request.getRequestor()+” - "+request.getFileName());

mNotificationId++;

// Gets an instance of the NotificationManager service

final NotificationManager mNotifyMgr =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

final int myNotificatioID=mNotificationId;

mNotifyMgr.notify(myNotificatioID, mBuilder.build());

new Thread(){

@Override

public void run() {

int progressBarStatus=0;

Log.i(“FileListener”,“Inside Thread Run”);

//showMessage(“It Seems something is sent to me! :-O”);

// startActivityForResult(resultIntent,FILE_TRANSFER_REQUEST_CODE);

File mf = Environment.getExternalStorageDirectory();

ReceivedFiledDirectory=Environment.getExternalStorageDirectory().getAbsolutePat h();

transferWrapper.transfer=request.accept();

try{

File file = new File(ReceivedFiledDirectory +"/"+ transferWrapper.transfer.getFileName());

ReceivedFiledDirectory="";

transferWrapper.transfer.recieveFile(file);

while(!transferWrapper.transfer.isDone())

{

try{

Thread.sleep(1000L);

}catch (Exception e) {

Log.e("", e.getMessage());

}

if(transferWrapper.transfer.getStatus().equals(Status.error)) {

Log.e("ERROR!!! ", transferWrapper.transfer.getError() + “”);

}

if(transferWrapper.transfer.getException() != null) {

transferWrapper.transfer.getException().printStackTrace();

}

progressBarStatus=(int)(100 * transferWrapper.transfer.getProgress());

mBuilder.setProgress(100, progressBarStatus, false);

mBuilder.setContentTitle(transferWrapper.transfer.getFileName());

mBuilder.setContentText("%"+progressBarStatus+" Transfered");

// Builds the notification and issues it.

mNotifyMgr.notify(myNotificatioID, mBuilder.build());

}

// ok, file is downloaded,

if (progressBarStatus >= 100)

{

// sleep 2 seconds, so that you can see the 100%

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

// When the loop is finished, updates the notification

mBuilder.setContentText(“Transfer complete”)

// Removes the progress bar

.setProgress(0,0,false);

mNotifyMgr.notify(mNotificationId, mBuilder.build());

// close the progress bar dialog

//progressBar.dismiss();

}

}catch (Exception e) {

Log.e(“File Transfer Listener”,“Exit Thread”);

}

};

}.start();

}

});

}

Please Like This Thread and Mark as Answered If this solution worked for you.

I’ll make a document of file transfer issues as soon as I have time.

Best Regards

1 Like

Is the problem related to http://community.igniterealtime.org/thread/49882 ??

In any case, it’d be better, if you just post your solution instead of keep it in PMs.

Hi CSH,

I know, and I’ll make a document on it soon,

at the time I’m so busy, and because of integration, I couldn’t post the whole solution,

But I’ll make a sample project, and implement simple file tarnsfer solution there for android using asmack, to be helpfull for others.

I’ll try to work on different situations that will cause problem and make a list to resolve each problem by help of other people who faces problems with file tarnsfer on android.

As you could see my problem was somthing else: The Receiver receives file transfer query but had no reaction, Listener didn’t triggered.

1 Like

I am facing problem 503-service unavailable Error during file transfer openfire

Hi,

I am developing chatting application in android with openfire server &asmack-jse-buddycloud.jar i am suffering to transfer files from one mobile to another mobile i refer the code from here linkhttp://www.javacodegeeks.com/2012/08/android-file-transfer-with-asmack-and.html/ comment-page-1/#comment-5365

Pls ping me solution in my below email address,

Thanks & Regards

prasadraju

email: prasadrajukonduru@gmail.com

You don’t need to configure the provider manager. Also how is this different from the existing documentation (e.g. http://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions/ filetransfer.html )?

Thanks a lot Flow,

It’s strange because I have’t find that document at time I was working on file transfer after hours of searching!!!

I Think when ommit config provider, I faced with service unavailble error from the other client in bytestream mode.

It seems some parts like file transfer looks different when come to android asmack client according to my experience.

Also enabling File Transfer Proxy in OpenFire sever is a good practice to overcome some issues caused by networing structure and NAT in ByteStream Socks5 file transfer.

Hi, i am also trying to establish p2p communications between ipcamera and android device . i am getting the response from camera. like

how can i parse these values in my android code. The xmpp libjingle library provide any methods for this.?

How can i re transfer the packet to camera.Any one can help me please.