Hi,
I’m using asmack to design a chat Android Application using a private ejabberd server.
Basic functions (add contact, send and receive message are working) but now I’m trying to transfert files between clients.
Trying in Java only before implement android environment I use the following classes.
import java.io.File;
import java.io.IOException;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;public class SendTest {
public static void main( String[] args ) { SmackConfiguration.setPacketReplyTimeout(45000); System.out.println("Starting IM client"); // gtalk requires this or your messages bounce back as errors ConnectionConfiguration connConfig = new ConnectionConfiguration("localhost", 5222, "localhost"); XMPPConnection connection = new XMPPConnection(connConfig); connConfig.setSASLAuthenticationEnabled(true); try { connection.connect(); System.out.println("Connected to " + connection.getHost()); } catch (XMPPException ex) { //ex.printStackTrace(); System.out.println("Failed to connect to " + connection.getHost()); System.exit(1); } try { connection.login("ben", "123456789"); System.out.println("Logged in as " + connection.getUser()); } catch (XMPPException ex) { //ex.printStackTrace(); System.out.println("Failed to log in as " + connection.getUser()); System.exit(1); } // Create the file transfer manager FileTransferManager manager = new FileTransferManager(connection); // Create the outgoing file transfer OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("test@localhost/Smack"); // Send the file try { transfer.sendFile(new File("C:/Documents and Settings/Chat.txt"), "You won't believe this!"); while(!transfer.isDone()) { System.out.println(transfer.getProgress() + " is done!"); System.out.println(transfer.getStreamID() + " is done!"); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Press enter to disconnect"); try { System.in.read(); } catch (IOException ex) { //ex.printStackTrace(); } connection.disconnect(); }
}
And
import java.io.File;
import java.io.IOException;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smackx.filetransfer.FileTransferListener;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.filetransfer.FileTransferRequest;
import org.jivesoftware.smackx.filetransfer.IncomingFileTransfer;public class ReceiveTest {
public static void main( String args ) {
SmackConfiguration.setPacketReplyTimeout(45000);
System.out.println(“Starting IM client”);// gtalk requires this or your messages bounce back as errors ConnectionConfiguration connConfig = new ConnectionConfiguration("localhost", 5222, "localhost"); XMPPConnection connection = new XMPPConnection(connConfig); connConfig.setSASLAuthenticationEnabled(true); try { connection.connect(); System.out.println("Connected to " + connection.getHost()); } catch (XMPPException ex) { //ex.printStackTrace(); System.out.println("Failed to connect to " + connection.getHost()); System.exit(1); } try { connection.login("test", "pass"); System.out.println("Logged in as " + connection.getUser()); Presence presence = new Presence(Presence.Type.available); connection.sendPacket(presence); } catch (XMPPException ex) { ex.printStackTrace(); System.out.println("Failed to log in as " + connection.getUser()); System.exit(1); } // Create the file transfer manager final FileTransferManager manager = new FileTransferManager(connection); // Create the listener manager.addFileTransferListener(new FileTransferListener() { public void fileTransferRequest(FileTransferRequest request) { // Accept it try { IncomingFileTransfer transfer = request.accept(); transfer.recieveFile(new File("Chat.txt")); System.out.println("File Received"); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); System.out.println("Press enter to disconnect"); try { System.in.read(); } catch (IOException ex) { //ex.printStackTrace(); } connection.disconnect(); }
}
It’s working perfectly with googleTalk but not with my ejabberd Server.
The Console display no error :
“”
Starting IM client
Connected to localhost
Logged in as ben@localhost/Smack
0.0 is done!
jsi_8583111514141398853 is done!
Press enter to disconnect
“”“”
But the Receiver match nothing.
Sniffing the XMPP messages I can found this relevant packet :
<iq>
from='test@localhost/Smack'
to='ben@localhost/Smack'
id='45Db9-9'
type='error'
<error>
code='501'
TYPE='CANCEL'
<feature-not-implemented/>
xmlns="urn:etf:params:xml:ns:xmpp-stanzas
```
Maybe it’s the server witch is not well configurated. The mod_proxy65 is installed,
with default configuration. The port 7777 is open on server.
I have no idea how to solve this problem. Thank for your help!