From c80110013f16d8aa4e6e9801e01ce9ccab1e6592 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Thu, 23 Feb 2012 16:37:07 +0000 Subject: Allow non-standard ports on internal interface method diff --git a/src/com/isode/stroke/client/CoreClient.java b/src/com/isode/stroke/client/CoreClient.java index 828906c..c01d57a 100644 --- a/src/com/isode/stroke/client/CoreClient.java +++ b/src/com/isode/stroke/client/CoreClient.java @@ -128,20 +128,23 @@ public class CoreClient { */ public void connect(ClientOptions o) { options = o; - connect(jid_.getDomain()); + connect(jid_.getDomain(), 5222); } /** - * Connect to the specified host, overriding the standard lookup rules. + * Connect to the specified host, overriding the standard lookup rules for the JID. + * + * Internal method, do not use. * * @param host Host to connect to, non-null. + * @param port Default port to use if SRV fails. */ - public void connect(String host) { + public void connect(String host, int port) { options = new ClientOptions(); disconnectRequested_ = false; assert (connector_ == null); /* FIXME: Port Proxies */ - connector_ = Connector.create(host, networkFactories.getDomainNameResolver(), networkFactories.getConnectionFactory(), networkFactories.getTimerFactory()); + connector_ = Connector.create(host, networkFactories.getDomainNameResolver(), networkFactories.getConnectionFactory(), networkFactories.getTimerFactory(), port); connectorConnectFinishedConnection_ = connector_.onConnectFinished.connect(new Slot1() { public void call(Connection p1) { handleConnectorFinished(p1); diff --git a/src/com/isode/stroke/network/Connector.java b/src/com/isode/stroke/network/Connector.java index 01fd114..fba0b95 100644 --- a/src/com/isode/stroke/network/Connector.java +++ b/src/com/isode/stroke/network/Connector.java @@ -19,8 +19,8 @@ import java.util.Collection; public class Connector { - public static Connector create(String hostname, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory) { - return new Connector(hostname, resolver, connectionFactory, timerFactory); + public static Connector create(String hostname, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory, int defaultPort) { + return new Connector(hostname, resolver, connectionFactory, timerFactory, defaultPort); } public void setTimeoutMilliseconds(int milliseconds) { @@ -56,11 +56,12 @@ public class Connector { public final Signal1 onConnectFinished = new Signal1(); - private Connector(String hostname, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory) { + private Connector(String hostname, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory, int defaultPort) { this.hostname = hostname; this.resolver = resolver; this.connectionFactory = connectionFactory; this.timerFactory = timerFactory; + this.defaultPort = defaultPort; } private void handleServiceQueryResult(Collection result) { @@ -128,7 +129,7 @@ public class Connector { HostAddress address = addressQueryResults.get(0); addressQueryResults.remove(0); - int port = 5222; + int port = defaultPort; if (!serviceQueryResults.isEmpty()) { port = serviceQueryResults.get(0).port; } @@ -215,4 +216,5 @@ public class Connector { private boolean queriedAllServices = true; private Connection currentConnection; private SignalConnection currentConnectionConnectFinishedConnection; + private final int defaultPort; } -- cgit v0.10.2-6-g49f6