openfire 在外网情况下如何配置才能传输文件?请大神们指点

jiangpengyu2000 2013-10-31 04:21:42
用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();

}


...全文
478 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
上官丹意 2014-04-08
  • 打赏
  • 举报
回复
楼主解决了吗,求解决方法。
未来畅想 2014-01-15
  • 打赏
  • 举报
回复
请问解决了吗??我也遇见这个问题。请楼主指点。

1,092

社区成员

发帖
与我相关
我的任务
社区描述
云计算服务器、网络、虚拟化相关讨论
社区管理员
  • 服务器
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧