Tabnine Logo
Socket.isConnected
Code IndexAdd Tabnine to your IDE (free)

How to use
isConnected
method
in
java.net.Socket

Best Java code snippets using java.net.Socket.isConnected (Showing top 20 results out of 3,159)

origin: libgdx/libgdx

@Override
public boolean isConnected () {
  if (socket != null) {
    return socket.isConnected();
  } else {
    return false;
  }
}
origin: libgdx/libgdx

@Override
public boolean isConnected () {
  if (socket != null) {
    return socket.isConnected();
  } else {
    return false;
  }
}
origin: alibaba/canal

public boolean isConnected() {
  Socket socket = this.socket;
  if (socket != null) {
    return socket.isConnected();
  }
  return false;
}
origin: netty/netty

@Override
public boolean isActive() {
  return !socket.isClosed() && socket.isConnected();
}
origin: aws/aws-sdk-java

@Override
public boolean isConnected() {
  return sock.isConnected();
}
origin: jMonkeyEngine/jmonkeyengine

public boolean isConnected()
{
  if( sock == null )
    return false;
  return sock.isConnected();
}
origin: redisson/redisson

@Override
public boolean isActive() {
  return !socket.isClosed() && socket.isConnected();
}
origin: wildfly/wildfly

@Override
public boolean isActive() {
  return !socket.isClosed() && socket.isConnected();
}
origin: robovm/robovm

/**
 * Returns the remote address and port of this socket as a {@code
 * SocketAddress} or null if the socket is not connected.
 *
 * @return the remote socket address and port.
 */
public SocketAddress getRemoteSocketAddress() {
  if (!isConnected()) {
    return null;
  }
  return new InetSocketAddress(getInetAddress(), getPort());
}
origin: apache/zookeeper

/**
 * See {@link Socket#isConnected()}. Calling this method does not trigger mode detection.
 */
@Override
public boolean isConnected() {
  return getSocketAllowUnknownMode().isConnected();
}
origin: stackoverflow.com

 Socket s = new Socket();

System.out.println("isConnected: " + s.isConnected() +
         " isBound: "     + s.isBound() +
         " isClosed: "    + s.isClosed());

s.connect(new InetSocketAddress("google.com", 80));

System.out.println("isConnected: " + s.isConnected() +
          " isBound: "    + s.isBound() +
          " isClosed: "   + s.isClosed());

s.close();

System.out.println("isConnected: " + s.isConnected() +
          " isBound: "    + s.isBound() +
          " isClosed: "   + s.isClosed());
origin: robovm/robovm

/**
 * Returns the port number of the target host this socket is connected to, or 0 if this socket
 * is not yet connected.
 */
public int getPort() {
  if (!isConnected()) {
    return 0;
  }
  return impl.getPort();
}
origin: neo4j/neo4j

  @Override
  public void disconnect() throws IOException
  {
    if ( socket != null && socket.isConnected() )
    {
      socket.close();
    }
  }
}
origin: netty/netty

/**
 * Create a new instance from the given {@link Socket}
 *
 * @param parent    the parent {@link Channel} which was used to create this instance. This can be null if the
 *                  {@link} has no parent as it was created by your self.
 * @param socket    the {@link Socket} which is used by this instance
 */
public OioSocketChannel(Channel parent, Socket socket) {
  super(parent);
  this.socket = socket;
  config = new DefaultOioSocketChannelConfig(this, socket);
  boolean success = false;
  try {
    if (socket.isConnected()) {
      activate(socket.getInputStream(), socket.getOutputStream());
    }
    socket.setSoTimeout(SO_TIMEOUT);
    success = true;
  } catch (Exception e) {
    throw new ChannelException("failed to initialize a socket", e);
  } finally {
    if (!success) {
      try {
        socket.close();
      } catch (IOException e) {
        logger.warn("Failed to close a socket.", e);
      }
    }
  }
}
origin: sohutv/cachecloud

public boolean isConnected() {
 return socket != null && socket.isBound() && !socket.isClosed() && socket.isConnected()
   && !socket.isInputShutdown() && !socket.isOutputShutdown();
}
origin: wildfly/wildfly

public TcpConnection(Socket s, TcpServer server) throws Exception {
  this.sock=s;
  this.server=server;
  if(s == null)
    throw new IllegalArgumentException("Invalid parameter s=" + s);
  setSocketParameters(s);
  this.out=new DataOutputStream(createBufferedOutputStream(s.getOutputStream()));
  this.in=new DataInputStream(createBufferedInputStream(s.getInputStream()));
  this.connected=sock.isConnected();
  this.peer_addr=server.usePeerConnections()? readPeerAddress(s)
   : new IpAddress((InetSocketAddress)s.getRemoteSocketAddress());
  last_access=getTimestamp(); // last time a message was sent or received (ns)
}
origin: apache/kafka

  @Override
  public void run() {
    try {
      DataInputStream input = new DataInputStream(socket.getInputStream());
      DataOutputStream output = new DataOutputStream(socket.getOutputStream());
      while (socket.isConnected() && !socket.isClosed()) {
        int size = input.readInt();
        if (renegotiate.get()) {
          renegotiate.set(false);
          ((SSLSocket) socket).startHandshake();
        }
        byte[] bytes = new byte[size];
        input.readFully(bytes);
        output.writeInt(size);
        output.write(bytes);
        output.flush();
      }
    } catch (IOException e) {
      // ignore
    } finally {
      try {
        socket.close();
      } catch (IOException e) {
        // ignore
      }
    }
  }
};
origin: k9mail/k-9

private void createMocks()
    throws MessagingException, IOException, NoSuchAlgorithmException, KeyManagementException {
  mockTrustedSocketFactory = mock(TrustedSocketFactory.class);
  mockSocket = mock(Socket.class);
  outputStreamForMockSocket = new ByteArrayOutputStream();
  when(mockTrustedSocketFactory.createSocket(null, host, port, null))
      .thenReturn(mockSocket);
  when(mockSocket.getOutputStream()).thenReturn(outputStreamForMockSocket);
  when(mockSocket.isConnected()).thenReturn(true);
}
origin: k9mail/k-9

@Before
public void setUp() throws Exception {
  ServerSettings serverSettings = createServerSettings();
  when(mockStoreConfig.getInboxFolder()).thenReturn(Pop3Folder.INBOX);
  when(mockTrustedSocketFactory.createSocket(null, "server", 12345, null)).thenReturn(mockSocket);
  when(mockSocket.isConnected()).thenReturn(true);
  when(mockSocket.isClosed()).thenReturn(false);
  when(mockSocket.getOutputStream()).thenReturn(mockOutputStream);
  store = new Pop3Store(serverSettings, mockStoreConfig, mockTrustedSocketFactory);
}
origin: k9mail/k-9

@Test(expected = MessagingException.class)
public void open_whenSocketNotConnected_throwsMessagingException() throws Exception {
  when(mockSocket.isConnected()).thenReturn(false);
  addSettingsForValidMockSocket();
  settings.setAuthType(AuthType.PLAIN);
  Pop3Connection connection = new Pop3Connection(settings, mockTrustedSocketFactory);
  connection.open();
}
java.netSocketisConnected

Javadoc

Returns whether this socket is connected to a remote host.

Popular methods of Socket

  • close
    Closes the socket. It is not possible to reconnect or rebind to this socket thereafter which means a
  • <init>
    Creates an unconnected socket with the given socket implementation.
  • getOutputStream
    Returns an output stream to write data into this socket.
  • getInputStream
    Returns an input stream to read data from this socket.
  • connect
    Connects this socket to the given remote host address and port specified by the SocketAddress remote
  • setSoTimeout
    Sets this socket's SocketOptions#SO_TIMEOUT in milliseconds. Use 0 for no timeout. To take effect, t
  • getInetAddress
    Returns the IP address of the target host this socket is connected to, or null if this socket is not
  • setTcpNoDelay
    Sets this socket's SocketOptions#TCP_NODELAY option.
  • getPort
    Returns the port number of the target host this socket is connected to, or 0 if this socket is not y
  • isClosed
    Returns whether this socket is closed.
  • getRemoteSocketAddress
    Returns the remote address and port of this socket as a SocketAddress or null if the socket is not c
  • setKeepAlive
    Sets this socket's SocketOptions#SO_KEEPALIVE option.
  • getRemoteSocketAddress,
  • setKeepAlive,
  • bind,
  • setSoLinger,
  • setSendBufferSize,
  • setReceiveBufferSize,
  • getLocalAddress,
  • getLocalPort,
  • shutdownOutput

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getExternalFilesDir (Context)
  • putExtra (Intent)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • JList (javax.swing)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now