diff --git a/jsmpp/src/main/java/org/jsmpp/session/SMPPSession.java b/jsmpp/src/main/java/org/jsmpp/session/SMPPSession.java index 557b996..460a60d 100644 --- a/jsmpp/src/main/java/org/jsmpp/session/SMPPSession.java +++ b/jsmpp/src/main/java/org/jsmpp/session/SMPPSession.java @@ -219,7 +219,7 @@ public String connectAndBind(String host, int port, throw new IOException("Failed connecting"); } - conn = connFactory.createConnection(host, port); + conn = connFactory.createConnection(host, port, timeout); logger.info("Connected"); conn.setSoTimeout(getEnquireLinkTimer()); diff --git a/jsmpp/src/main/java/org/jsmpp/session/connection/ConnectionFactory.java b/jsmpp/src/main/java/org/jsmpp/session/connection/ConnectionFactory.java index 88c445e..406a774 100644 --- a/jsmpp/src/main/java/org/jsmpp/session/connection/ConnectionFactory.java +++ b/jsmpp/src/main/java/org/jsmpp/session/connection/ConnectionFactory.java @@ -22,4 +22,5 @@ */ public interface ConnectionFactory { Connection createConnection(String host, int port) throws IOException; + Connection createConnection(String host, int port, long timeout) throws IOException; } diff --git a/jsmpp/src/main/java/org/jsmpp/session/connection/socket/SocketConnectionFactory.java b/jsmpp/src/main/java/org/jsmpp/session/connection/socket/SocketConnectionFactory.java index efefea4..53e94a9 100644 --- a/jsmpp/src/main/java/org/jsmpp/session/connection/socket/SocketConnectionFactory.java +++ b/jsmpp/src/main/java/org/jsmpp/session/connection/socket/SocketConnectionFactory.java @@ -15,6 +15,7 @@ package org.jsmpp.session.connection.socket; import java.io.IOException; +import java.net.InetSocketAddress; import java.net.Socket; import org.jsmpp.session.connection.Connection; @@ -38,4 +39,11 @@ public Connection createConnection(String host, int port) throws IOException { return new SocketConnection(new Socket(host, port)); } + public Connection createConnection(String host, int port, long timeout) + throws IOException { + Socket soc = new Socket(); + InetSocketAddress endpoint = new InetSocketAddress(host, port); + soc.connect(endpoint, (int)timeout); + return new SocketConnection(soc); + } }