Fixes in Echo

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7049 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Thiago Camargo 2007-02-08 22:36:54 +00:00 committed by thiago
parent 2cc661a189
commit 23d27b9ffc
1 changed files with 9 additions and 6 deletions

View File

@ -368,9 +368,7 @@ public abstract class TransportCandidate {
* check if the transport candidate the other endpoint has provided is
* usable.
* <p/>
* This method provides a basic check where it sends a "ping" to the remote
* address provided in the candidate. If the "ping" succedess, the candidate
* is accepted. Subclasses should provide better methods if they can...
* Subclasses should provide better methods if they can...
*/
public void check() {
//TODO candidate is being checked trigger
@ -383,7 +381,7 @@ public abstract class TransportCandidate {
InetAddress candAddress;
try {
candAddress = InetAddress.getByName(getIp());
isUsable = true;//candAddress.isReachable(CHECK_TIMEOUT);
isUsable = candAddress.isReachable(TransportResolver.CHECK_TIMEOUT);
}
catch (Exception e) {
isUsable = false;
@ -933,19 +931,22 @@ public abstract class TransportCandidate {
boolean enabled = true;
public CandidateEcho(TransportCandidate candidate) throws UnknownHostException, SocketException {
this.socket = new DatagramSocket(candidate.getPort(), InetAddress.getByName(candidate.getLocalIp()));
this.socket = new DatagramSocket(candidate.getPort(), InetAddress.getByName("0.0.0.0"));
Random r = new Random();
password = longToByteArray((Math.abs(r.nextLong())));
}
public void run() {
try {
System.out.println("Listening for ECHO: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort());
while (true) {
DatagramPacket packet = new DatagramPacket(new byte[8], 8);
socket.receive(packet);
System.out.println("ECHO Packet Received in: " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " From: " + packet.getAddress().getHostAddress() + ":" + packet.getPort());
for (DatagramListener listener : listeners) {
listener.datagramReceived(packet);
}
@ -977,7 +978,7 @@ public abstract class TransportCandidate {
}
public boolean test(final InetAddress address, final int port) {
return test(address,port,2000);
return test(address, port, 2000);
}
public boolean test(final InetAddress address, final int port, int timeout) {
@ -1019,6 +1020,8 @@ public abstract class TransportCandidate {
e.printStackTrace();
}
this.removeListener(listener);
return testResults.isReachable();
}