diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java
index 6aa8dc1..a75e652 100644
--- a/src/org/ice4j/ice/CandidatePair.java
+++ b/src/org/ice4j/ice/CandidatePair.java
@@ -731,32 +731,15 @@ public class CandidatePair
if (base != null)
localCandidate = base;
- if (localCandidate instanceof TcpHostCandidate)
+ RemoteCandidate remoteCandidate = getRemoteCandidate();
+ if (remoteCandidate != null)
{
- /*
- * TcpHostCandidates can have multiple sockets, and the one
- * to be used by this specific CandidatePair has to have the
- * same remote socket address as the pair's remote candidate.
- */
- RemoteCandidate remoteCandidate = getRemoteCandidate();
- if (remoteCandidate == null)
- return null;
-
- SocketAddress remoteSocketAddress
+ SocketAddress remoteAddress
= remoteCandidate.getTransportAddress();
- for (IceSocketWrapper socket
- : ((TcpHostCandidate) localCandidate).getIceSocketWrappers())
- {
- if (socket.getTCPSocket()
- .getRemoteSocketAddress().equals(remoteSocketAddress))
- return socket;
- }
- }
- else
- {
- return localCandidate.getIceSocketWrapper();
+ if (remoteAddress != null)
+ return localCandidate.getIceSocketWrapper(remoteAddress);
}
- return null;
+ return localCandidate.getIceSocketWrapper();
}
}
diff --git a/src/org/ice4j/ice/LocalCandidate.java b/src/org/ice4j/ice/LocalCandidate.java
index 6352636..a16e8a7 100644
--- a/src/org/ice4j/ice/LocalCandidate.java
+++ b/src/org/ice4j/ice/LocalCandidate.java
@@ -122,6 +122,20 @@ public abstract class LocalCandidate
*/
protected abstract IceSocketWrapper getIceSocketWrapper();
+ /**
+ * Gets the IceSocketWrapper associated with this
+ * Candidate which is to be used for a specific remote address.
+ * This default implementation ignores the remote address.
+ *
+ * @param remoteAddress the remote address for which to get a socket.
+ * @return the IceSocketWrapper associated with this
+ * Candidate which is to be used for a specific remote address.
+ */
+ protected IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress)
+ {
+ return getIceSocketWrapper();
+ }
+
/**
* Creates if necessary and returns a DatagramSocket that would
* capture all STUN packets arriving on this candidate's socket. If the
diff --git a/src/org/ice4j/ice/TcpHostCandidate.java b/src/org/ice4j/ice/TcpHostCandidate.java
index 1d16572..d475e50 100644
--- a/src/org/ice4j/ice/TcpHostCandidate.java
+++ b/src/org/ice4j/ice/TcpHostCandidate.java
@@ -73,8 +73,16 @@ public class TcpHostCandidate
super.free();
}
- public List getIceSocketWrappers()
+ @Override
+ protected IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress)
{
- return sockets;
+ for (IceSocketWrapper socket : sockets)
+ {
+ if (socket.getTCPSocket().getRemoteSocketAddress()
+ .equals(remoteAddress))
+ return socket;
+ }
+
+ return null;
}
}