@Override public boolean isConnected () { if (socket != null) { return socket.isConnected(); } else { return false; } }
@Override public boolean isConnected () { if (socket != null) { return socket.isConnected(); } else { return false; } }
public boolean isConnected() { Socket socket = this.socket; if (socket != null) { return socket.isConnected(); } return false; }
@Override public boolean isActive() { return !socket.isClosed() && socket.isConnected(); }
@Override public boolean isConnected() { return sock.isConnected(); }
public boolean isConnected() { if( sock == null ) return false; return sock.isConnected(); }
@Override public boolean isActive() { return !socket.isClosed() && socket.isConnected(); }
@Override public boolean isActive() { return !socket.isClosed() && socket.isConnected(); }
/** * 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()); }
/** * See {@link Socket#isConnected()}. Calling this method does not trigger mode detection. */ @Override public boolean isConnected() { return getSocketAllowUnknownMode().isConnected(); }
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());
/** * 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(); }
@Override public void disconnect() throws IOException { if ( socket != null && socket.isConnected() ) { socket.close(); } } }
/** * 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); } } } }
public boolean isConnected() { return socket != null && socket.isBound() && !socket.isClosed() && socket.isConnected() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
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) }
@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 } } } };
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); }
@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); }
@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(); }