cgl.narada.transport.ptcp.psocket
Class PTCPSocket

java.lang.Object
  extended by java.net.Socket
      extended by cgl.narada.transport.ptcp.psocket.PTCPSocket
All Implemented Interfaces:
PTCPParameters

public class PTCPSocket
extends Socket
implements PTCPParameters

Title:

Description:

Copyright: Copyright (c) 2004

Company:

Version:
1.0

Field Summary
 
Fields inherited from interface cgl.narada.transport.ptcp.psocket.tools.PTCPParameters
COMM_SOCKET, DATA_SOCKET, PTCPBuffer_Debug, PTCPDataFragmentator_Debug, PTCPInputStream_Debug, PTCPOutputStream_Debug, PTCPPacket_Debug, PTCPReceiverWorker_Debug, PTCPSenderWorker_Debug, PTCPServerSocket_Debug, PTCPSocket_Debug, PTCPSocketInfo_Debug
 
Constructor Summary
PTCPSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int num)
          creates a socket and connects it to the specified remote address on the specified remote port.
PTCPSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int num, boolean incPrf)
           
PTCPSocket(InetAddress address, int port, int num)
          Constructor.
PTCPSocket(InetAddress address, int port, int num, boolean incPrf)
           
PTCPSocket(int num)
           
PTCPSocket(int num, boolean incPrf)
           
PTCPSocket(String host, int port, InetAddress localAddr, int localPort, int num)
          Creates a socket and connects it to the specified remote host on the specified remote port.
PTCPSocket(String host, int port, InetAddress localAddr, int localPort, int num, boolean incPrf)
           
PTCPSocket(String host, int port, int num)
          Constructor.
PTCPSocket(String host, int port, int num, boolean incPrf)
           
 
Method Summary
 void addSocket(Socket[] sockets)
           
 void addSocket(Socket[] sockets, Socket commSock)
           
 InputStream getCommInputStream()
          Get input stream for commands.
 OutputStream getCommOutputStream()
          Get output stream for commands.
 InetAddress getInetAddress()
          Returns the address to which the socket is connected.
 InputStream getInputStream()
          Returns an input stream for this socket.
 boolean getKeepAlive()
          Tests if SO_KEEPALIVE is enabled.
 InetAddress getLocalAddress()
          Gets the local address to which the socket is bound.
 int getLocalPort()
          Returns the local port to which this socket is bound.
 int getNumberOfStreams()
           
 OutputStream getOutputStream()
          Returns an output stream for this socket.
 int getPort()
          Returns the remote port to which this socket is connected.
 int getReceiveBufferSize()
          Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.
 int getRTT()
           
 int getSendBufferSize()
          Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.
 int getSoLinger()
          Returns setting for SO_LINGER.
 int getSoTimeout()
          Returns setting for SO_TIMEOUT.
 boolean getTcpNoDelay()
          Tests if TCP_NODELAY is enabled.
 long getTxEndTime()
           
 long getTxStartTime()
           
 boolean isConnected()
          Returns the connection state of the socket.
 boolean isIncrPerf()
           
 void setIncreasePerformanceOption()
           
 void setIncrPerf(boolean incrPerf)
           
 void setKeepAlive(boolean on)
          Enable/disable SO_KEEPALIVE.
 void setReceiveBufferSize(int size)
          Sets the SO_RCVBUF option to the specified value for this Socket.
 void setRTT(int rtt)
           
 void setSendBufferSize(int size)
          Sets the SO_SNDBUF option to the specified value for this Socket.
 void setSoLinger(boolean on, int linger)
          Enable/disable SO_LINGER with the specified linger time in seconds.
 void setSoTimeout(int timeout)
          Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
 void setTcpNoDelay(boolean on)
          Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
 void setTxEndTime(long txEndTime)
           
 void setTxStartTime(long txStartTime)
           
 void shutdownInput()
          Places the input stream for this socket at "end of stream".
 void shutdownOutput()
          Disables the output stream for this socket.
 String toString()
          Converts this socket to a String.
 
Methods inherited from class java.net.Socket
bind, close, connect, connect, getChannel, getLocalSocketAddress, getOOBInline, getRemoteSocketAddress, getReuseAddress, getTrafficClass, isBound, isClosed, isInputShutdown, isOutputShutdown, sendUrgentData, setOOBInline, setPerformancePreferences, setReuseAddress, setSocketImplFactory, setTrafficClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PTCPSocket

public PTCPSocket(int num)

PTCPSocket

public PTCPSocket(int num,
                  boolean incPrf)

PTCPSocket

public PTCPSocket(String host,
                  int port,
                  int num)
Constructor. Creates a stream socket and connects it to the specified port number on the named host.

Parameters:
host - remote host name.
port - remote server port.
num - number of parallel streams.

PTCPSocket

public PTCPSocket(String host,
                  int port,
                  int num,
                  boolean incPrf)

PTCPSocket

public PTCPSocket(InetAddress address,
                  int port,
                  int num)
Constructor. Creates a stream socket and connects it to the specified port number on the specified address.

Parameters:
address - remote internet address.
port - remote server port.
num - number of parallel streams.

PTCPSocket

public PTCPSocket(InetAddress address,
                  int port,
                  int num,
                  boolean incPrf)

PTCPSocket

public PTCPSocket(String host,
                  int port,
                  InetAddress localAddr,
                  int localPort,
                  int num)
Creates a socket and connects it to the specified remote host on the specified remote port. The Socket will also bind() to the local address and port supplied.


PTCPSocket

public PTCPSocket(String host,
                  int port,
                  InetAddress localAddr,
                  int localPort,
                  int num,
                  boolean incPrf)

PTCPSocket

public PTCPSocket(InetAddress address,
                  int port,
                  InetAddress localAddr,
                  int localPort,
                  int num)
creates a socket and connects it to the specified remote address on the specified remote port. The Socket will also bind() to the local address and port supplied.


PTCPSocket

public PTCPSocket(InetAddress address,
                  int port,
                  InetAddress localAddr,
                  int localPort,
                  int num,
                  boolean incPrf)
Method Detail

getCommInputStream

public InputStream getCommInputStream()
                               throws IOException
Get input stream for commands.

Throws:
IOException

getCommOutputStream

public OutputStream getCommOutputStream()
                                 throws IOException
Get output stream for commands.

Throws:
IOException

getInetAddress

public InetAddress getInetAddress()
Returns the address to which the socket is connected.

Overrides:
getInetAddress in class Socket

getInputStream

public InputStream getInputStream()
                           throws IOException
Returns an input stream for this socket.

Overrides:
getInputStream in class Socket
Throws:
IOException

setKeepAlive

public void setKeepAlive(boolean on)
                  throws SocketException
Enable/disable SO_KEEPALIVE.

Overrides:
setKeepAlive in class Socket
Throws:
SocketException

getKeepAlive

public boolean getKeepAlive()
                     throws SocketException
Tests if SO_KEEPALIVE is enabled.

Overrides:
getKeepAlive in class Socket
Throws:
SocketException

getLocalAddress

public InetAddress getLocalAddress()
Gets the local address to which the socket is bound.

Overrides:
getLocalAddress in class Socket

getLocalPort

public int getLocalPort()
Returns the local port to which this socket is bound.

Overrides:
getLocalPort in class Socket

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Returns an output stream for this socket.

Overrides:
getOutputStream in class Socket
Throws:
IOException

getPort

public int getPort()
Returns the remote port to which this socket is connected.

Overrides:
getPort in class Socket

setRTT

public void setRTT(int rtt)

getRTT

public int getRTT()

setReceiveBufferSize

public void setReceiveBufferSize(int size)
Sets the SO_RCVBUF option to the specified value for this Socket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers. Increasing buffer size can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data. For UDP, this sets the maximum size of a packet that may be sent on this Socket. Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to should call getReceiveBufferSize().

Overrides:
setReceiveBufferSize in class Socket

getReceiveBufferSize

public int getReceiveBufferSize()
Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.

Overrides:
getReceiveBufferSize in class Socket

setSendBufferSize

public void setSendBufferSize(int size)
                       throws SocketException
Sets the SO_SNDBUF option to the specified value for this Socket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers. Increasing buffer size can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data. For UDP, this sets the maximum size of a packet that may be sent on this Socket. Because SO_SNDBUF is a hint, applications that want to verify what size the buffers were set to should call getSendBufferSize(). Parameters:

Overrides:
setSendBufferSize in class Socket
Throws:
SocketException

getSendBufferSize

public int getSendBufferSize()
                      throws SocketException
Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.

Overrides:
getSendBufferSize in class Socket
Throws:
SocketException

setSoLinger

public void setSoLinger(boolean on,
                        int linger)
                 throws SocketException
Enable/disable SO_LINGER with the specified linger time in seconds. The maximum timeout value is platform specific. The setting only affects socket close.

Overrides:
setSoLinger in class Socket
Throws:
SocketException

getSoLinger

public int getSoLinger()
                throws SocketException
Returns setting for SO_LINGER. -1 returns implies that the option is disabled. The setting only affects socket close.

Overrides:
getSoLinger in class Socket
Throws:
SocketException

setIncreasePerformanceOption

public void setIncreasePerformanceOption()

setSoTimeout

public void setSoTimeout(int timeout)
                  throws SocketException
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.io.InterruptedIOException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

Overrides:
setSoTimeout in class Socket
Throws:
SocketException

getSoTimeout

public int getSoTimeout()
                 throws SocketException
Returns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

Overrides:
getSoTimeout in class Socket
Throws:
SocketException

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws SocketException
Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).

Overrides:
setTcpNoDelay in class Socket
Throws:
SocketException

getTcpNoDelay

public boolean getTcpNoDelay()
                      throws SocketException
Tests if TCP_NODELAY is enabled.

Overrides:
getTcpNoDelay in class Socket
Throws:
SocketException

setTxEndTime

public void setTxEndTime(long txEndTime)

getTxEndTime

public long getTxEndTime()

setTxStartTime

public void setTxStartTime(long txStartTime)

getTxStartTime

public long getTxStartTime()

addSocket

public void addSocket(Socket[] sockets)

addSocket

public void addSocket(Socket[] sockets,
                      Socket commSock)

shutdownInput

public void shutdownInput()
                   throws IOException
Places the input stream for this socket at "end of stream". Any data sent to the input stream side of the socket is acknowledged and then silently discarded. If you read from a socket input stream after invoking shutdownInput() on the socket, the stream will return EOF.

Overrides:
shutdownInput in class Socket
Throws:
IOException

shutdownOutput

public void shutdownOutput()
                    throws IOException
Disables the output stream for this socket. For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.

Overrides:
shutdownOutput in class Socket
Throws:
IOException

toString

public String toString()
Converts this socket to a String.

Overrides:
toString in class Socket

isConnected

public boolean isConnected()
Returns the connection state of the socket.

Overrides:
isConnected in class Socket
Returns:
true if the socket successfuly connected to a server TODO: Implement this java.net.Socket method

isIncrPerf

public boolean isIncrPerf()

setIncrPerf

public void setIncrPerf(boolean incrPerf)

getNumberOfStreams

public int getNumberOfStreams()


For comments and suggestions please send e-mail to The NaradaBrokering Project