This is how I try to send a file over XMPP using asmack lib (from the GtalkSms project) and a Ejabberd server:
//Configure provider in onCreate()
configure(ProviderManager.getInstance());
// Configure function
private void configure(ProviderManager pm){
pm.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
pm.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
pm.addIQProvider("open","http://jabber.org/protocol/ibb", new OpenIQProvider());
pm.addIQProvider("close","http://jabber.org/protocol/ibb", new CloseIQProvider());
pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider());
}
// This is how I send file after login to server (I put everything below in a
function, inside a Thread and call thread.start() at the end of function):
// set the serviceDiscoveryManager
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(xmppConn);
if (sdm == null){
sdm = new ServiceDiscoveryManager(xmppConn);
}
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
// Create the file transfer manager
FileTransferManager manager = new FileTransferManager(connection);
FileTransferNegotiator.setServiceEnabled(connection, true);
OutgoingFileTransfer transfer = manager
.createOutgoingFileTransfer(Receiver
+ "#MyDomain");
transfer.sendFile(new File(myFilePath), "myDescription");
If I use another client to test the file transfer (http://coccinella.im/), then I can chat and send a file over my Ejarbberd server between (2 coccinella clients). If I use a coccinella client and my client in android, I can chat between them and I can receive file sent from coccinella client to my android client. However, when I try to send file from my android client to the coccinella client, transfer.isDone() always returns true and transfer.getStatus() == Status.error also returns true.
So what's happen to my Android client? Did I use wrong library? Or I missed something?
Edited: This is what I got from debugger: <iq id="QgJIb-29" to="phuocdh#localhost/Smack" from="phuoctest#localhost/Coccinella#phuocdh-pc" type="error"><error code="404" type="CANCEL"><item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost></streamhost></query></error></iq>
Related
I am trying to implement a FTP file upload in android, using Apache commons library. The communication must be done through explicit TLS authentication. I can login, connect to server and list files successfully, but when i am trying to store a file to the server, it creates a file in the destination folder of the server with size 0 and throwing SSLException: Write error, broken pipe.
How to overcome this?
Below is my code:
FTPSClient ftpClient = new FTPSClient("TLS", false);
ftpClient.addProtocolCommandListener(new PrintCommandListener(new
KeyManagerFactory kmf = getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(null, null);
KeyManager km = kmf.getKeyManagers()[0];
ftpClient.setKeyManager(km);
ftpClient.setBufferSize(1000);
ftpClient.setConnectTimeout(5000);
ftpClient.connect(InetAddress.getByName("server ip address"), 990);
// Set protection buffer size
ftpClient.execPBSZ(0);
// // Set data channel protection to private
ftpClient.execPROT("P");
ftpClient.login("username", "password");
ftpClient.changeWorkingDirectory("/");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
buffInp = new BufferedInputStream(new FileInputStream(file.getAbsolutePath()));
//throwing exception here
boolean status = ftpClient.storeFile( picture.getName(), buffInp );
I am using Pjusa for Voip, I have done communication through UDP and TCP but could not communitcate through TLS setting`
TlsConfig tlsConfig = new TlsConfig();
File cacheDir = new File(ctx.getCacheDir(), "ca");
InputStream input = ctx.getResources().openRawResource(R.raw.ca);
tlsConfig.setCaListFile(cacheDir.getPath());
input = ctx.getResources().openRawResource(R.raw.secure);
cacheDir = new File(ctx.getCacheDir(), "secure");
tlsConfig.setCertFile(cacheDir.getPath());
tlsConfig.setMethod(pjsip_ssl_method.PJSIP_SSLV23_METHOD);`
I have attached CaListFile and setCertFile files like that method and that setting working but When I establish a call then I found error like that
tlsc0x9e7db014 TLS connect() error: Connection refused [code=120111]
tsx0x9d945864 Failed to send Request msg INVITE/cseq=25416 (tdta0x9d991000)! err=120111 (Connection refused)
In IOS I found some more setting for TLS , but could not implement in PJSUA
any one can help me out how to use that piece of code in android in PJSUA library
pj_sockaddr_in remote;
pjsip_transport *transport;
remote.sin_family = pj_AF_INET();
remote.sin_zero_len = 0;
remote.sin_addr.s_addr = pj_inet_addr(#"xxx.xx.xx.xx").s_addr;
remote.sin_addr.s_addr = INADDR_ANY;
bzero(&(remote.sin_zero),sizeof(remote.sin_zero));
app_config->cfg.use_srtp = PJMEDIA_SRTP_MANDATORY;
app_config->cfg.srtp_secure_signaling = 1;
thanks in advance
TlsConfig tlsConfig = new TlsConfig();
tlsConfig.setCertFile(certFile);
sipTpConfig.setTlsConfig(tlsConfig);
tlsConfig.setCaListFile(caListFile);
I did R&D from web searching and reading document of SIP and PJSIP, then I find the sluotion for accountConfig for PJMEDIA_SRTP_MANDATORY and setSrtpSecureSignaling(1) by that way provided below
accCfg.getMediaConfig().setSrtpUse(pjmedia_srtp_use.PJMEDIA_SRTP_MANDATORY);
accCfg.getMediaConfig().setSrtpSecureSignaling(1);
Hence TLS working with CAListFile and CertificateFile
I am trying to enable TOR support on my own XMPP app in android. I am using orbot as TOR proxy and I have the following code to connect app socket:
socket = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 9050)));
socket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
but I am getting Malformed reply from SOCKS server even that my Orbot is up and running. I believe that this error is thrown when app cant access proxy server or mentioned server is not SOCKS proxy.
I have also tried to use jsocks:
Socks5Proxy sProxy = new Socks5Proxy("127.0.0.1", 9050);
sProxy.resolveAddrLocally(false);
String host = account.getServer().toString();
int port = 5222;
System.out.println(host + ":" + port);
try {
socket = new SocksSocket(sProxy, host, port);
}catch(SocksException sock_ex){
System.err.println("SocksException:"+sock_ex);
}
System.out.println("here we are");
where host is "jabbim.com"
But I never get to "here we are" println so it looks like my app hangs somewhere on creating SocksSocket but I am not getting any errors either. When I debug it it hangs on impl.getInputStream somewhere in jsocks (PlainSocketImpl I believe)
Any idea how to fix this?
Thanks in forward
I solved this using
compile "org.igniterealtime.smack:smack-android-extensions:4.1.4"
compile "org.igniterealtime.smack:smack-tcp:4.1.4"
and then connecting using this code:
final Random rndForTorCircuits = new Random();
String user = rndForTorCircuits.nextInt(100000) + "";
String pass = rndForTorCircuits.nextInt(100000) + "";
ProxyInfo proxyInfo = new ProxyInfo(ProxyInfo.ProxyType.SOCKS5, "127.0.0.1", 9050, user, pass);
socket = proxyInfo.getSocketFactory().createSocket(addr.getHostName(), addr.getPort());
by using this you get socket that is already connected to proxy.
I try to use ektorp client for replication in android and I have an error :
org.ektorp.DocumentNotFoundException: nothing found on db path: /_replicate, Response body: {"error":"not_found","reason":"unknown URL"}
I installed a gateway and a CouchBase server.
I access to the url /sync_gateway, but the client try to reach /sync_gateway/_replicate.
What's this ??? and what I have to do to make it work ????
Thank you by advance
Best regards
My code :
// start Ektorp adapter
HttpClient httpClient = new AndroidHttpClient.Builder()
.host("XXX")
.username("XXX")
.password("XXX")
.port(4984)
.build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// create a local database
CouchDbConnector dbConnector = new StdCouchDbConnector("sync_gateway", dbInstance);
// pull this database to the test replication server
ReplicationCommand pullCommand = new ReplicationCommand.Builder()
.source("sync_gateway")
.target("XXX")
.continuous(true)
.build();
ReplicationStatus status = dbInstance.replicate(pullCommand);
I try to connect a Pc with and Android device via TCPp using the eneter library
When I send data from the android device to the PC, data is transferred and answer back to android is received immediately but I get problems transfering data from PC to the android device
With the following code the PC is sending the data to itself because I receive the data on the OnMessageReceived procedure of the C# code not in the android
public NCProgram()
{
aReceiverFactory = new DuplexTypedMessagesFactory();
myReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver<MyResponse, MyRequest>();
mySender = aReceiverFactory.CreateDuplexTypedMessageSender<MyResponse, MyRequest>();
// Subscribe to handle messages.
myReceiver.MessageReceived += OnMessageReceived;
mySender.ResponseReceived += OnResponseReceived;
// Create TCP messaging.
IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://192.168.173.1:6060/");
IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://192.168.173.1:6060/");
// Attach the input channel and start to listen to messages.
myReceiver.AttachDuplexInputChannel(anInputChannel);
// Attach output channel to the sender and be able to send
// request messages and receive responses.
mySender.AttachDuplexOutputChannel(anOutputChannel);
m_TexteRebut = "Comunicació establerta";
}
public void Enviar()
{
MyRequest aRequestMessage = new MyRequest();
aRequestMessage.Text = m_Texte_Enviar;
mySender.SendRequestMessage(aRequestMessage);
}
If I don't use the the outputchannel and I send the message as if it was an answer to a communication from the android device, then the data are transferred to the android device but sometimes it takes one second, sometimes a few ones and sometimes 20 or 30 seconds.
public NCProgram()
{
aReceiverFactory = new DuplexTypedMessagesFactory();
myReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver<MyResponse, MyRequest>();
//mySender = aReceiverFactory.CreateDuplexTypedMessageSender<MyResponse, MyRequest>();
// Subscribe to handle messages.
myReceiver.MessageReceived += OnMessageReceived;
//mySender.ResponseReceived += OnResponseReceived;
// Create TCP messaging.
IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("tcp://192.168.173.1:6060/");
//IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://192.168.173.1:6060/");
// Attach the input channel and start to listen to messages.
myReceiver.AttachDuplexInputChannel(anInputChannel);
// Attach output channel to the sender and be able to send
// request messages and receive responses.
//mySender.AttachDuplexOutputChannel(anOutputChannel);
m_TexteRebut = "Comunicació establerta";
}
public void Enviar()
{
MyRequest aRequestMessage = new MyRequest();
aRequestMessage.Text = m_Texte_Enviar;
myReceiver.SendResponseMessage(IPAddress,aRequestMessage);
}
Any advice on how to solve the communication from PC to android device will be appreciated