org.mobicents.protocols.smpp.net
Class TcpLink

java.lang.Object
  extended by org.mobicents.protocols.smpp.net.AbstractStreamLink
      extended by org.mobicents.protocols.smpp.net.TcpLink
All Implemented Interfaces:
SmscLink

public class TcpLink
extends AbstractStreamLink

Implementation of an Smsc link over the tcp/ip protocol

Version:
$Id: TcpLink.java 452 2009-01-15 16:56:36Z orank $
Author:
amit bhayani, orank

Field Summary
static int DEFAULT_PORT
          Default IP port to use if none are specified.
 
Constructor Summary
TcpLink(InetAddress address)
          Create a new TcpLink
TcpLink(InetAddress address, int port)
          Create a new TcpLink
TcpLink(Socket socket)
          Create a new TcpLink object around an existing socket.
TcpLink(String address)
          Create a new TcpLink
TcpLink(String address, int port)
          Create a new TcpLink
 
Method Summary
 void connect()
          Initiate the connection to the SMSC.
 void disconnect()
          Close the connection to the SMSC.
 InetAddress getAddress()
          Get the address we're connected (or connecting) to.
 int getConnectedPort()
          Get the port at the SMSC that this link is connected to.
protected  InputStream getInputStream()
          Get the input stream of the Socket connection to the SMSC.
 int getLocalPort()
          Get the local port number this link is connected to.
protected  OutputStream getOutputStream()
          Get the output stream of the Socket connection to the SMSC.
 int getPort()
          Get the service port to connect to at the SMSC to establish a TCP connection.
 int getTimeout()
          Get the current timeout for the underlying link.
 boolean isConnected()
          Determine if the underlying link is connected to the SMSC.
 boolean isTimeoutSupported()
          Determine if this SMSC link supports read timeouts.
 void setTimeout(int timeout)
          Set the socket timeout.
 
Methods inherited from class org.mobicents.protocols.smpp.net.AbstractStreamLink
available, flush, getAutoFlush, read, setAutoFlush, setInputStream, setOutputStream, setSnoopStreams, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
Default IP port to use if none are specified.

See Also:
Constant Field Values
Constructor Detail

TcpLink

public TcpLink(String address)
        throws UnknownHostException
Create a new TcpLink

Parameters:
address - IP address or hostname of SMSC
Throws:
UnknownHostException - If the host is not found.

TcpLink

public TcpLink(String address,
               int port)
        throws UnknownHostException
Create a new TcpLink

Parameters:
address - IP address or hostname of SMSC
port - The port number to connect to
Throws:
UnknownHostException - If the host is not found.

TcpLink

public TcpLink(InetAddress address)
Create a new TcpLink

Parameters:
address - IP address SMSC
Throws:
UnknownHostException - If the host is not found.

TcpLink

public TcpLink(InetAddress address,
               int port)
Create a new TcpLink

Parameters:
address - IP address of SMSC
port - The port number to connect to
Throws:
UnknownHostException - If the host is not found.

TcpLink

public TcpLink(Socket socket)
        throws IOException
Create a new TcpLink object around an existing socket.

Parameters:
socket - The socket to use for communications.
Throws:
IOException
Method Detail

getAddress

public InetAddress getAddress()
Get the address we're connected (or connecting) to.

Returns:
The address of the SMSC this link is connected to.

getPort

public int getPort()
Get the service port to connect to at the SMSC to establish a TCP connection.

Returns:
The service port at the SMSC to connect to.

getConnectedPort

public int getConnectedPort()
                     throws IOException
Get the port at the SMSC that this link is connected to. This is the remote port that this link is connected to after a successful connection has been made.

Returns:
The remote port this link is connected to.
Throws:
IOException - If the connection is not open.

getLocalPort

public int getLocalPort()
                 throws IOException
Get the local port number this link is connected to.

Returns:
The local port number this link is connected to.
Throws:
IOException - If the connection is not open.

isConnected

public boolean isConnected()
Description copied from interface: SmscLink
Determine if the underlying link is connected to the SMSC.

Returns:
true if connected, false otherwise.

setTimeout

public void setTimeout(int timeout)
Set the socket timeout. This SmscLink implementation uses SO_TIMEOUT to implement read timeouts.

Parameters:
timeout - The timeout to set.
See Also:
SmscLink.setTimeout(int)

getTimeout

public int getTimeout()
Description copied from interface: SmscLink
Get the current timeout for the underlying link. If read timeouts are not supported, calls to this method should throw a UnsupportedOperationException.

Returns:
The current timeout, specified in milliseconds.
See Also:
SmscLink.setTimeout(int)

isTimeoutSupported

public boolean isTimeoutSupported()
Description copied from interface: SmscLink
Determine if this SMSC link supports read timeouts.

Returns:
true if the implementation supports read timeouts, false if not.

connect

public void connect()
             throws IOException
Description copied from interface: SmscLink
Initiate the connection to the SMSC. If this link is already connected, this method should do nothing.

Throws:
IOException

disconnect

public void disconnect()
                throws IOException
Description copied from class: AbstractStreamLink
Close the connection to the SMSC. Calling this method will close the network link to the remote SMSC system. Applications should be unbound from the SMPP link (using Session.unbind()) before closing the underlying network link. The connection may be reestablished using #open.

Specified by:
disconnect in interface SmscLink
Overrides:
disconnect in class AbstractStreamLink
Throws:
IOException

getOutputStream

protected OutputStream getOutputStream()
                                throws IOException
Get the output stream of the Socket connection to the SMSC.

Throws:
IOException - If the socket connection is not open or an I/O error occurs when creating the output stream.
See Also:
OutputStream, Socket.getOutputStream()

getInputStream

protected InputStream getInputStream()
                              throws IOException
Get the input stream of the Socket connection to the SMSC.

Throws:
IOException - If the socket connection is not open or an I/O error occurs when creating the input stream.
See Also:
InputStream, Socket.getInputStream()


Copyright © 2011 Mobicents. All Rights Reserved.