SocketChannel isConnected - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SocketChannel isConnected method.

This code example shows how to use the following methods:connect, finishConnect, isConnected, isConnectionPending, close
        this.channel1.close();
        assertFalse(this.channel1.isOpen());
    } 
 
    public void testIsConnected() throws Exception {
        assertFalse(this.channel1.isConnected());// not connected
        this.channel1.configureBlocking(false);
        assertFalse(this.channel1.connect(localAddr1));
        assertFalse(this.channel1.isConnected());
        assertTrue(this.channel1.isConnectionPending());
        assertTrue(tryFinish());
        assertTrue(this.channel1.isConnected());
        this.channel1.close();
        assertFalse(this.channel1.isConnected());
    } 
 
    public void testIsConnectionPending() throws Exception {
        // ensure 
        ensureServerClosed(); 
        this.channel1.configureBlocking(false);

7
CodeRank
This code example shows how to use the following methods:isConnected, isOpen
  /** 
   * Checks whether the socket is connected. 
   */ 
  public boolean isOpen() { 
    // isConnected() does not return false after close(), but isOpen() does 
    return socketChannel_.isOpen() && socketChannel_.isConnected();
  } 
 
  /** 
   * Do not call, the implementation provides its own lazy non-blocking connect. 
   */ 
  public void open() throws TTransportException { 
    throw new RuntimeException("open() is not implemented for TNonblockingSocket");
  } 
 
  /** 
   * Perform a nonblocking read into buffer. 
   */ 
  public int read(ByteBuffer buffer) throws IOException {
    return socketChannel_.read(buffer);
6
CodeRank
This code example shows how to use the following methods:isConnected
        return socketChannel.socket();
    } 
 
    @Override 
    public boolean isConnected() { 
        return socketChannel.isConnected();
    } 
 
    @Override 
    public boolean connect(SocketAddress socketAddress) throws IOException {
        return socketChannel.connect(socketAddress);
    } 
 
    @Override 
    public int read(ByteBuffer byteBuffer) throws IOException {
        return socketChannel.read(byteBuffer);
    } 
 
    @Override 
    public int write(ByteBuffer byteBuffer) throws IOException {
6
CodeRank
This code example shows how to use the following methods:register, connect, finishConnect, isConnected
    @Override 
    public boolean connect(SocketAddress remote) throws IOException {
 
        long start = System.currentTimeMillis();
        //log.debug("trying to connect"); 
        socketChannel.connect(remote);
        while (selector.select(connectTimeout) > 0) {
            selector.selectedKeys().remove(channelKey);
            //log.debug("selected connect"); 
            //log.debug("Spent " + (System.currentTimeMillis() - start)); 
            if (!channelKey.isConnectable()) {
                throw new IllegalStateException("Socket channel is in not connectable state");
            } 
 
            socketChannel.finishConnect();
            channelKey = socketChannel.register(selector, SelectionKey.OP_READ);
            if (log.isDebugEnabled()) { 
                log.debug("Connected socket in " + (System.currentTimeMillis() - start));
            } 
            if (!socketChannel.isConnected()) {

6
CodeRank
This code example shows how to use the following methods:isConnected, socket, configureBlocking
   * @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);

6
CodeRank
This code example shows how to use the following methods:isConnected, close
        _socketChannel.socket().setTcpNoDelay(true);
    } 
 
     
    public boolean isConnected() { 
        return _socketChannel != null && _socketChannel.isConnected();
    } 
 
    public SocketChannel getReadChannel() throws IOException {
        return getChannel(); 
    } 
 
    public SocketChannel getWriteChannel() throws IOException {
        return getChannel(); 
    } 
 
    private SocketChannel getChannel() throws IOException {
 
        if (!isConnected()) { 
            connect(); 

5
CodeRank
This code example shows how to use the following methods:connect, finishConnect, isConnected, isConnectionPending, close
        this.channel1.close();
        assertFalse(this.channel1.isOpen());
    } 
 
    public void testIsConnected() throws Exception { 
        assertFalse(this.channel1.isConnected());// not connected
        this.channel1.configureBlocking(false);
        assertFalse(this.channel1.connect(localAddr1));
        assertFalse(this.channel1.isConnected());
        assertTrue(this.channel1.isConnectionPending());
        assertTrue(tryFinish());
        assertTrue(this.channel1.isConnected());
        this.channel1.close();
        assertFalse(this.channel1.isConnected());
    } 
 
    public void testIsConnectionPending() throws Exception { 
        // ensure 
        ensureServerClosed(); 
        this.channel1.configureBlocking(false);

6
CodeRank
This code example shows how to use the following methods:register, connect, finishConnect, isConnected
    @Override 
    public boolean connect(SocketAddress remote) throws IOException {
 
        long start = System.currentTimeMillis();
        //log.debug("trying to connect"); 
        socketChannel.connect(remote);
        while (selector.select(connectTimeout) > 0) {
            selector.selectedKeys().remove(channelKey);
            //log.debug("selected connect"); 
            //log.debug("Spent " + (System.currentTimeMillis() - start)); 
            if (!channelKey.isConnectable()) {
                throw new IllegalStateException("Socket channel is in not connectable state");
            } 
 
            socketChannel.finishConnect();
            channelKey = socketChannel.register(selector, SelectionKey.OP_READ);
            if (log.isDebugEnabled()) {
                log.debug("Connected socket in " + (System.currentTimeMillis() - start));
            } 
            if (!socketChannel.isConnected()) {

5
CodeRank
This code example shows how to use the following methods:isConnected, socket, configureBlocking
   * @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);

5
CodeRank
This code example shows how to use the following methods:isConnected, write, close
isConnected Method Overview
Tells whether or not this channel's network socket is connected.
See Code Examples for other Java 8 SocketChannel Methods: