Now the exchange of data work some times.
But i think the exchenge should be in the MediaSession not in the callback
--- a/src/com/beem/project/beem/jingle/Caller.java Thu Mar 12 23:45:49 2009 +0100
+++ b/src/com/beem/project/beem/jingle/Caller.java Thu Mar 12 23:46:51 2009 +0100
@@ -1,15 +1,22 @@
package com.beem.project.beem.jingle;
+import java.net.UnknownHostException;
+
import java.util.ArrayList;
import java.util.List;
+
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
+
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.JingleSession;
+
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
+
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.PayloadType;
+
import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
@@ -72,11 +79,26 @@
final TransportCandidate localCandidate,
final JingleSession jingleSession) {
System.out.println("Session established");
- String name = remoteCandidate.getName();
- String ip = remoteCandidate.getIp();
- int port = remoteCandidate.getPort();
- System.out.println("Session established avec "+name+" sur "+ ip + ":" +port);
-
+ String name = localCandidate.getName();
+ String ip = localCandidate.getIp();
+ int port = localCandidate.getPort();
+ System.out.println("Session established waiting connection on " + ip + ":" +port);
+ try {
+ try{
+ FileSender fs = new FileSender(ip, port, "/tmp/img.jpeg");
+ fs.start();
+ fs.join();
+ System.out.println("End of transfer");
+ } finally {
+ jingleSession.terminate();
+ }
+ } catch (UnknownHostException e ) {
+ System.err.println("Can't create server");
+ } catch (InterruptedException e){
+ } catch (XMPPException e) {
+ System.err.println("Probably lost the connection");
+ e.printStackTrace();
+ }
}
@Override
--- a/src/com/beem/project/beem/jingle/Receiver.java Thu Mar 12 23:45:49 2009 +0100
+++ b/src/com/beem/project/beem/jingle/Receiver.java Thu Mar 12 23:46:51 2009 +0100
@@ -80,8 +80,8 @@
// TODO Auto-generated method stub
System.out.println("Session established");
try{
- System.out.println("Je recois sur " + localCandidate.getIp() + ":" + localCandidate.getPort() );
- receiveData(localCandidate.getIp(), localCandidate.getPort());
+ System.out.println("Je recois sur " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort() );
+ receiveData(remoteCandidate.getIp(), remoteCandidate.getPort());
} catch (IOException e){
e.printStackTrace();
}
@@ -119,12 +119,10 @@
private void receiveData(String ip, int port) throws IOException {
- ServerSocket serv = null;
Socket s = null;
try {
- serv = new ServerSocket(port);
+ s = new Socket(ip, port);
System.out.println("Waiting data");
- s = serv.accept();
InputStream in = s.getInputStream();
int a;
while ( (a = in.read()) != -1) {
@@ -132,8 +130,6 @@
}
System.out.println("End receiving data");
} finally {
- if (serv != null)
- serv.close();
if (s != null)
s.close();
}
--- a/src/com/beem/project/beem/jingle/SenderMediaSession.java Thu Mar 12 23:45:49 2009 +0100
+++ b/src/com/beem/project/beem/jingle/SenderMediaSession.java Thu Mar 12 23:46:51 2009 +0100
@@ -16,7 +16,6 @@
public class SenderMediaSession extends JingleMediaSession {
private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaSession.class);
- private static final String filename = "/tmp/test.jpg";
private boolean active = false;
private boolean started = false;
private FileSender fileSender;
@@ -41,7 +40,6 @@
*/
@Override
public void initialize() {
- fileSender = new FileSender(this.getRemote().getIp(), getRemote().getPort(), filename);
}
/* (non-Javadoc)
@@ -67,7 +65,6 @@
*/
@Override
public void startTrasmit() {
- fileSender.start();
}
/* (non-Javadoc)