1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +01:00

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

View file

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