Commit 20500bd7 authored by Thiago Camargo's avatar Thiago Camargo Committed by thiago

Cancel Channels without using stop() in Threads.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6602 b35dd754-fafc-0310-a699-88a17e54d16e
parent 20ccc788
...@@ -20,7 +20,7 @@ import java.net.InetAddress; ...@@ -20,7 +20,7 @@ import java.net.InetAddress;
* MediaProxy create and bind relay channels between IP pairs. * MediaProxy create and bind relay channels between IP pairs.
* This relay can provite UDP connectivity between two parties that are behind NAT. * This relay can provite UDP connectivity between two parties that are behind NAT.
* It also work to provide connectivity between two parties that are directly connected to the internet or one party in the internet and another behind a NAT. * It also work to provide connectivity between two parties that are directly connected to the internet or one party in the internet and another behind a NAT.
* The RTPPRoxy Class add and control the Bridge Agents. * The MediaProxy Class add and control the Bridge Agents.
* You can setup a MediaProxy for all your network interfaces with a empty constructor, * You can setup a MediaProxy for all your network interfaces with a empty constructor,
* or bind it to an especific interface with MediaProxy(String localhost) constructor. * or bind it to an especific interface with MediaProxy(String localhost) constructor.
* <i>This MediaProxy ONLY works if your are Direct Connected to the Internet with a valid IP address.</i> * <i>This MediaProxy ONLY works if your are Direct Connected to the Internet with a valid IP address.</i>
......
...@@ -2,9 +2,9 @@ package org.jivesoftware.wildfire.mediaproxy; ...@@ -2,9 +2,9 @@ package org.jivesoftware.wildfire.mediaproxy;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import java.util.*;
import java.net.*;
import java.io.IOException; import java.io.IOException;
import java.net.*;
import java.util.*;
/** /**
* A media proxy session enables two clients to exchange UDP traffic. Each client connects to * A media proxy session enables two clients to exchange UDP traffic. Each client connects to
...@@ -218,10 +218,10 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -218,10 +218,10 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
channelBtoAControl.removeListener(); channelBtoAControl.removeListener();
try { try {
threadAtoB.stop(); channelAtoB.cancel();
threadAtoBControl.stop(); channelAtoBControl.cancel();
threadBtoA.stop(); channelBtoA.cancel();
threadBtoAControl.stop(); channelBtoAControl.cancel();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -415,7 +415,6 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -415,7 +415,6 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
/** /**
* Removes every Session events listeners * Removes every Session events listeners
*
*/ */
public void clearAgentListeners() { public void clearAgentListeners() {
sessionListeners.clear(); sessionListeners.clear();
...@@ -441,6 +440,7 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -441,6 +440,7 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
protected byte[] buf = new byte[5000]; protected byte[] buf = new byte[5000];
protected DatagramSocket dataSocket; protected DatagramSocket dataSocket;
protected DatagramPacket packet; protected DatagramPacket packet;
protected boolean enabled = true;
List<DatagramListener> listeners = new ArrayList<DatagramListener>(); List<DatagramListener> listeners = new ArrayList<DatagramListener>();
...@@ -520,6 +520,11 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -520,6 +520,11 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
listeners.removeAll(listeners); listeners.removeAll(listeners);
} }
public void cancel() {
this.enabled = false;
dataSocket.close();
}
/** /**
* Thread override method * Thread override method
*/ */
...@@ -534,10 +539,10 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -534,10 +539,10 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
if (this.getPort() != packet.getPort()) if (this.getPort() != packet.getPort())
System.out.println(dataSocket.getLocalAddress().getHostAddress() + ":" + dataSocket.getLocalPort() + " relay to: " + packet.getAddress().getHostAddress() + ":" + packet.getPort()); System.out.println(dataSocket.getLocalAddress().getHostAddress() + ":" + dataSocket.getLocalPort() + " relay to: " + packet.getAddress().getHostAddress() + ":" + packet.getPort());
if (c++ < 5){ if (c++ < 5) {
System.out.println("Received:" + dataSocket.getLocalAddress().getHostAddress() + ":" + dataSocket.getLocalPort()); System.out.println("Received:" + dataSocket.getLocalAddress().getHostAddress() + ":" + dataSocket.getLocalPort());
System.out.println("Addr: "+packet.getAddress().getHostName()); System.out.println("Addr: " + packet.getAddress().getHostName());
} }
boolean resend = true; boolean resend = true;
...@@ -554,12 +559,15 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -554,12 +559,15 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
} }
} }
catch (UnknownHostException uhe) { catch (UnknownHostException uhe) {
if (enabled)
Log.error(uhe); Log.error(uhe);
} }
catch (SocketException se) { catch (SocketException se) {
if (enabled)
Log.error(se); Log.error(se);
} }
catch (IOException ioe) { catch (IOException ioe) {
if (enabled)
Log.error(ioe); Log.error(ioe);
} }
} }
......
...@@ -143,11 +143,14 @@ public class SmartSession extends MediaProxySession { ...@@ -143,11 +143,14 @@ public class SmartSession extends MediaProxySession {
} }
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
if(enabled)
System.err.println("Unknown Host"); System.err.println("Unknown Host");
} }
catch (SocketException e) { catch (SocketException e) {
if(enabled)
System.err.println("Socket closed"); System.err.println("Socket closed");
} catch (IOException e) { } catch (IOException e) {
if(enabled)
System.err.println("Communication error"); System.err.println("Communication error");
e.printStackTrace(); e.printStackTrace();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment