Code example for SocketChannel

Methods: isConnectedsocketconfigureBlocking

0
   * @param socketChannel Already created SocketChannel object 
   * @throws IOException if there is an error setting up the streams 
   */ 
  public TNonblockingSocket(SocketChannel socketChannel) throws IOException {
    this(socketChannel, 0, null);
    if (!socketChannel.isConnected()) throw new IOException("Socket must already be connected");
  } 
 
  private TNonblockingSocket(SocketChannel socketChannel, int timeout, SocketAddress socketAddress)
      throws IOException { 
    socketChannel_ = socketChannel;
    socketAddress_ = socketAddress;
 
    // make it a nonblocking channel 
    socketChannel.configureBlocking(false);
 
    // set options 
    Socket socket = socketChannel.socket();
    socket.setSoLinger(false, 0);
    socket.setTcpNoDelay(true);
    setTimeout(timeout);
  }