Quantcast
Channel: Ignite Realtime : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 10742

problem about file transfer

$
0
0

Hi everyone,

I have some questions about file transfer on openfire. I was following steps on offical documents.

http://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions/ index.html

Here is my code:

1) send file

publicvoid onClick(View v){                              FileTransferManager manager=new FileTransferManager(ConstantUtils.conn2);                              OutgoingFileTransfer transfer=manager.createOutgoingFileTransfer(ConstantUtils.chatname+"@srong/Smack");                              File file=new File("/mnt/sdcard/test1.jpg");                              System.out.println("begin to send file");                              try{                                        transfer.sendFile(file,"hahaha");                              }catch (XMPPException e) {                                        // TODO Auto-generated catch block                                         e.printStackTrace();                              }                              System.out.println("done(send file)");                              while(!transfer.isDone()){                                        if(transfer.getStatus().equals(Status.error)){                                                  System.out.println("ERROR!!!"+transfer.getError());                                        }elseif(transfer.getStatus().equals(Status.cancelled)||transfer.getStatus().equals(Status.refused)){                                                  System.out.println("Canceled!!!"+transfer.getError());                                        }                                        try{                                                  Thread.sleep(1000L);                                        }catch(InterruptedException e){                                                  e.printStackTrace();                                        }                              }                              if(transfer.getStatus().equals(Status.refused)||transfer.getStatus().equals(Status.error)||transfer.getStatus().equals(Status.cancelled)){                                        System.out.println("refused cancelled error "+transfer.getError());                              }else{                                        System.out.println("Success");                              }                    } 

 

2)receive file

FileTransferManager manager=new FileTransferManager(ConstantUtils.conn2);                              manager.addFileTransferListener(new FileTransferListener(){                                        publicvoid fileTransferRequest(final FileTransferRequest request){                                                  new Thread(){                                                            publicvoid run(){                                                                      IncomingFileTransfer transfer=request.accept();                                                                      File mf=Environment.getExternalStorageDirectory();                                                                      File file=new File(mf.getAbsoluteFile()+"/DCIM/Camera/"+transfer.getFileName());                                                                      try{                                                                                transfer.recieveFile(file);                                                                                while(!transfer.isDone()){                                                                                          try{                                                                                                    Thread.sleep(1000L);                                                                                          }catch(Exception e){                                                                                                    e.printStackTrace();                                                                                          }                                                                                          if(transfer.getStatus().equals(Status.error)){                                                                                                    System.out.println("error"+transfer.getError());                                                                                          }                                                                                          if(transfer.getException()!=null){                                                                                                    transfer.getException().printStackTrace();                                                                                          }                                                                                }                                                                      }catch(Exception e){                                                                                System.out.println(e.getMessage());                                                                      }                                                            };                                                  }.start();                                        }                              }); 

While eclipse send:

refused cancelled error null

It stopped when I send a  file at

if(transfer.getStatus().equals(Status.refused)||transfer.getStatus().equals(Status.error)||transfer.getStatus().equals(Status.cancelled)){                                        System.out.println("refused cancelled error "+transfer.getError());                              }else{                                        System.out.println("Success");                              } 

But the error is null. I don't know how to slove it.

 

Thank you all.

Strong Su


Viewing all articles
Browse latest Browse all 10742

Trending Articles