com.ibm.net

Class SocketUtils

  1. java.lang.Object
  2. extended bycom.ibm.net.SocketUtils

  1. public class SocketUtils
  2. extends java.lang.Object
Utility class for java.net.Socket. Developers need to guard against concurrency and consistency check between the Java object and their own use of the native sockets, retrieved by the methods provided by this class. For eg. if the Java Socket/ServerSocket/SocketChannel /ServerSocketChannel is closed, previously obtained value for the native socket and any further operations with the native socket is invalid.

Constructor Summary

Constructor and Description
SocketUtils()

Method Summary

Modifier and Type Method and Description
  1. static
  2. void
configureKeepAlive(java.net.Socket s,SocketKeepAliveParameters p)
Control behaviour of socket keepalives for the supplied Socket.
  1. static
  2. long[]
getFileDescriptor(java.net.ServerSocket s)
Retrieve the value of the Socket descriptor represented by the supplied ServerSocket.
  1. static
  2. long[]
getFileDescriptor(java.nio.channels.ServerSocketChannel channel)
Retrieve the value of the Socket descriptor represented by the supplied ServerSocketChannel.
  1. static
  2. long[]
getFileDescriptor(java.net.Socket s)
Retrieve the value of the Socket descriptor represented by the supplied Socket.
  1. static
  2. long[]
getFileDescriptor(java.nio.channels.SocketChannel channel)
Retrieve the value of the Socket descriptor represented by the supplied SocketChannel.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

SocketUtils

  1. public SocketUtils()

Method Detail

configureKeepAlive

  1. public static void configureKeepAlive( java.net.Socket s,
  2. SocketKeepAliveParameters p)
  3. throws java.net.SocketException
Control behaviour of socket keepalives for the supplied Socket. To enable or disable socket keepalives use Socket.setKeepAlive(boolean). e.g. To enable keepalive and set the keepalive idle time for this socket to 1 hour and keepalive interval to 20 seconds:
     java.net.Socket s = serverSocket.accept();
     s.setKeepAlive(true); // Enable keepalive using existing java.net.Socket API
     com.ibm.net.SocketKeepAliveParameters p = new com.ibm.net.SocketKeepAliveParameters();
     p.setIdleTime(1*60*60); // Set keepalive idle time to 1 hour
     p.setIntervalTime(20); // Set keepalive interval to 20 seconds
     com.ibm.net.SocketUtils.configureKeepAlive(s, p);
     ...
 
Parameters:
s - The Socket to configure.
p - The SocketKeepAliveParameters containing the values to set.
Throws:
java.net.SocketException - If an error occurs while setting the keepalive parameters.
See Also:
SocketKeepAliveParameters, Socket.setKeepAlive(boolean)

getFileDescriptor

  1. public static long[] getFileDescriptor( java.nio.channels.SocketChannel channel)
Retrieve the value of the Socket descriptor represented by the supplied SocketChannel.
Parameters:
channel - SocketChannel.
Returns:
The value of the socket represented by the supplied SocketChannel. In case of Windows (Windows XP and Windows 2003), where IPv6 is enabled, it returns an array of 2 socket descriptors, else a single element array will be returned containing the value of the native socket descriptor. It returns -1 if the socket is closed.

getFileDescriptor

  1. public static long[] getFileDescriptor( java.nio.channels.ServerSocketChannel channel)
Retrieve the value of the Socket descriptor represented by the supplied ServerSocketChannel.
Parameters:
channel - ServerSocketChannel.
Returns:
The value of the socket represented by the supplied ServerSocketChannel. In case of Windows (Windows XP and Windows 2003), where IPv6 is enabled, it returns an array of 2 socket descriptors, else a single element array will be returned containing the value of the native socket descriptor. It returns -1 if the socket is closed.

getFileDescriptor

  1. public static long[] getFileDescriptor( java.net.Socket s)
Retrieve the value of the Socket descriptor represented by the supplied Socket.
Parameters:
s - Socket.
Returns:
The value of the socket represented by the supplied Socket. In case of Windows (Windows XP and Windows 2003), where IPv6 is enabled, it returns an array of 2 socket descriptors, else a single element array will be returned containing the value of the native socket descriptor. It returns -1 if the socket is closed.

getFileDescriptor

  1. public static long[] getFileDescriptor( java.net.ServerSocket s)
Retrieve the value of the Socket descriptor represented by the supplied ServerSocket.
Parameters:
s - ServerSocket.
Returns:
The value of the socket represented by the supplied ServerSocket. In case of Windows (Windows XP and Windows 2003), where IPv6 is enabled, it returns an array of 2 socket descriptors, else a single element array will be returned containing the value of the native socket descriptor. It returns -1 if the socket is closed.