To configure proper proxy add/change these 3 properties in Openfire:
- xmpp.proxy.enabled – true
- xmpp.proxy.port – 7777
- xmpp.proxy.externalip – [publicly accessible host or ip]
After setting proxy enabled and port to 7777 you can use the library as
asmack-jse-buddycloud.jar
Code to send file:
FileTransferManager manager =
new
FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(
"usre2@myHost/Smack"
);
File file =
new
File(filenameWithPath);
try
{
transfer.sendFile(file,
"test_file"
);
}
catch
(XMPPException e) {
e.printStackTrace();
}
while
(!transfer.isDone()) {
if
(transfer.getStatus().equals(Status.error)) {
System.out.println(
"ERROR!!! "
+ transfer.getError());
}
else
if
(transfer.getStatus().equals(Status.cancelled)
|| transfer.getStatus().equals(Status.refused)) {
System.out.println(
"Cancelled!!! "
+ 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"
);
}
Code to recieve file:
Also configure ProviderManager to properly decode/parse bytestreams and other required xmls:
ProviderManager.getInstance().addIQProvider(
"query"
,
"http://jabber.org/protocol/bytestreams"
,
new
BytestreamsProvider());
ProviderManager.getInstance().addIQProvider(
"query"
,
"http://jabber.org/protocol/disco#items"
,
new
DiscoverItemsProvider());
ProviderManager.getInstance().addIQProvider(
"query"
,
"http://jabber.org/protocol/disco#info"
,
new
DiscoverInfoProvider());
If you need more help you can mail me at maidaragi1919@gmail.com
0 comments:
Post a Comment