openfire 在外网情况下如何配置才能传输文件?请大神们指点
用asmack写的安卓客户端,在内网情况下测式,手机能发能接,但外网情况下就传不了,什么原因啊.文件发送:
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);
final long timeOut = 1000000;
final long sleepMin = 3000;
new Thread(new Runnable() {
public void run() {
try {
int rs = 0;
long spTime = 0;
outfiletransfer.sendFile(new java.io.File(audioPath),
"send file");
rs = outfiletransfer.getStatus().compareTo(
FileTransfer.Status.complete);
while (rs != 0) {
spTime = spTime + sleepMin;
if (spTime > timeOut) {
return;
}
Thread.sleep(sleepMin);
}
toast.setText("发送成功");
toast.show();
} catch (Exception e) {
toast.setText("发送失败");
toast.show();
}
}
}).start();
}
接收:
public void receivedFile(){
/**
* 接收文件
*/
// Create the file transfer manager
Thread thread = new Thread() {
public void 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);
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
.accept();
String path = Constant.FILE_ROOT_PATH;
File file1 = new File(path);
file1.mkdirs();
String body = null;
final String filePath = Constant.FILE_ROOT_PATH
+ request.getFileName();
File file = new File(filePath);
if (request.getFileName().contains("mp3")) {
body = "语音消息";
} else if (request.getFileName()
.contains("mp4")) {
body = "视频消息";
}
// 自己显示消息
Msg myChatMsg = new Msg(user.getUsername()
+ "@" + friendJID.split("@")[0], user
.getUsername(),
friendJID.split("@")[0],
Constant.MSG_WAY_RECEIVE,
Constant.MSG_TYPE_TEXT, body,
TimeRender.getDate(), filePath);
// 在handler里取出来显示消息
android.os.Message msg = ChatRoomActivity.handler
.obtainMessage();
msg.what = Constant.WHAT_MSG_CHANGE;
msg.obj = myChatMsg;
msg.sendToTarget();
try {
if (!file.exists()) {
Log.i("have no file", file.getPath());
file.createNewFile();
}
transfer.recieveFile(file);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
};
thread.start();
}
补充:云计算 , 服务器