Home > other >  Openfire outer net circumstances how to configure to transfer files? The great god, please give dire
Openfire outer net circumstances how to configure to transfer files? The great god, please give dire

Time:10-04

Written in asmack android client, under the condition of network type, mobile phone can send can meet, but the network circumstances can't pass, what reason.
File sent:
Public void sendFile (final String audioPath) {

//Create the file transfer manager
ServiceDiscoveryManager SDM=ServiceDiscoveryManager
GetInstanceFor (XMPPTool. Getconnection ());
If (SDM==null)
SDM=new ServiceDiscoveryManager (XMPPTool getconnection ());
SDM. AddFeature (" http://jabber.org/protocol/disco#info ");
SDM. AddFeature (jabber: IQ: "privacy");

Final Toast Toast=Toast. MakeText (this, "", Toast. LENGTH_LONG);
FileTransferManager sendFilemanager=new FileTransferManager (
XMPPTool. Getconnection ());
FileTransferNegotiator
SetServiceEnabled (XMPPTool. Getconnection (), true);
Final OutgoingFileTransfer outfiletransfer=sendFilemanager
CreateOutgoingFileTransfer (friend. GetFriendJID () + "/"
+ Constant. MY_RESOUCE_NAME);

The final long timeOut=1000000;
The final long sleepMin=3000;

New Thread (new Runnable () {
Public void the run () {

Try {

Int the rs=0;
Long spTime=0;

Outfiletransfer. SendFile (new Java. IO. The File (audioPath),
"Send file");

Rs=outfiletransfer. GetStatus (). CompareTo (
FileTransfer.Status.com plete);
While (rs!=0) {
SpTime=spTime + sleepMin;
If (spTime & gt; The timeOut) {
return;
}
Thread.sleep (sleepMin);

}

Toast. SetText (" send success ");
Toast. The show ();

} the catch (Exception e) {

Toast. SetText (" failure ");
Toast. The show ();

}

}
}). The start ();
}


Reception:
Public void receivedFile () {
/* *
* receive file
*/
//Create the file transfer manager

Thread the Thread=new Thread () {
Public void the run () {
ServiceDiscoveryManager SDM=ServiceDiscoveryManager
GetInstanceFor (XMPPTool. Getconnection ());
If (SDM==null)
SDM=new ServiceDiscoveryManager (XMPPTool getconnection ());

SDM. AddFeature (" http://jabber.org/protocol/disco#info ");

SDM. AddFeature (jabber: IQ: "privacy");

Final FileTransferManager managerListner=new FileTransferManager (
XMPPTool. Getconnection ());
FileTransferNegotiator. SetServiceEnabled (
XMPPTool. Getconnection (), true);
The Log. I (" File transfere manager ", "created");

ManagerListner
AddFileTransferListener (new FileTransferListener () {

@ Override
Public void fileTransferRequest (
Final FileTransferRequest request) {
//TODO Auto - generated method stub

IncomingFileTransfer transfer request of=
The accept ();
String path=Constant. FILE_ROOT_PATH;
The File file1=new File (path);
File1. The file.mkdirs ();
String body=null;
Final String filePath=Constant. FILE_ROOT_PATH
+ request. GetFileName ();
The File File=new File (filePath);
If (request. GetFileName (). The contains (" mp3 ")) {
The body="voice message";
} else if (request. GetFileName ()
The contains (" mp4 ")) {
Body="video news";
}

//their displays a message

Msg myChatMsg=new Msg (user getUsername ()
+ "@" + friendJID. Split (" @ ") [0], the user
GetUsername (),
FriendJID. Split (" @ ") [0],
Constant MSG_WAY_RECEIVE,
Constant MSG_TYPE_TEXT, body,
TimeRender. GetDate (), filePath);

//in out to display the message handler
Android. OS. Message MSG=ChatRoomActivity. Handler
ObtainMessage ();
MSG. What=Constant. WHAT_MSG_CHANGE;
MSG. Obj=myChatMsg;

MSG. SendToTarget ();

Try {
if (! File. The exists ()) {
Log. I (" have no the file, the file. The getPath ());
File. CreateNewFile ();
}
Transfer. RecieveFile (file);

} the catch (Exception e) {
e.printStackTrace();
}

}

});
}

};
Thread. The start ();

}


CodePudding user response:

Is solved?? I also met this problem, the building Lord, please give directions,

CodePudding user response:

The building Lord solved, seek the solution,
  • Related