当前位置: 首页>>代码示例>>Java>>正文


Java Socket.isConnected方法代码示例

本文整理汇总了Java中java.net.Socket.isConnected方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.isConnected方法的具体用法?Java Socket.isConnected怎么用?Java Socket.isConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.Socket的用法示例。


在下文中一共展示了Socket.isConnected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkClientTrusted

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType,
    Socket socket) throws CertificateException {
  if (!option.isAuthPeer()) {
    return;
  }

  String ip = null;
  if (socket != null && socket.isConnected()
      && socket instanceof SSLSocket) {
    InetAddress inetAddress = socket.getInetAddress();
    if (inetAddress != null) {
      ip = inetAddress.getHostAddress();
    }
  }
  checkTrustedCustom(chain, ip);
  trustManager.checkClientTrusted(chain, authType, socket);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TrustManagerExt.java

示例2: checkServerTrusted

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType,
    Socket socket) throws CertificateException {
  if (!option.isAuthPeer()) {
    return;
  }

  String ip = null;
  if (socket != null && socket.isConnected()
      && socket instanceof SSLSocket) {
    InetAddress inetAddress = socket.getInetAddress();
    if (inetAddress != null) {
      ip = inetAddress.getHostAddress();
    }
  }
  checkTrustedCustom(chain, ip);
  trustManager.checkServerTrusted(chain, authType, socket);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TrustManagerExt.java

示例3: sendMessage

import java.net.Socket; //导入方法依赖的package包/类
/**
 * sendMessage Method
 * Send the message to TAS for control
 * @param containerName
 * @param content
 * @throws IOException
 */
public static void sendMessage(String containerName, String content) throws IOException {
	ArrayList<Container> containers = ResourceRepository.getContainersInfo();		
	Container tempContainer;
	
	for (int i = 0; i < containers.size(); i++) {
		tempContainer = containers.get(i);
		
		if (containerName.equals(tempContainer.ctname)) {
			Socket tasSocket = tempContainer.tasSocket;
			if (tasSocket.isConnected()) {
				PrintWriter writer = new PrintWriter(tasSocket.getOutputStream(), true);
				writer.println(content);
				System.out.println("[&CubeThyme] Send to TAS \"" + content + "\"\n");
			}
			else {
				System.out.println("[&CubeThyme] TAS connection is closed\n");
			}
		}
		else {
			System.out.println("[&CubeThyme] Could not found container\n");
		}
	}
}
 
开发者ID:IoTKETI,项目名称:nCube-Thyme-Java,代码行数:31,代码来源:TasSender.java

示例4: testIdle

import java.net.Socket; //导入方法依赖的package包/类
@Test(timeout = 1000)
public void testIdle() throws InterruptedException, IOException {
  Socket s = new Socket();
  try {
    s.connect(pm.getTcpServerLocalAddress());

    int i = 0;
    while (!s.isConnected() && i < RETRY_TIMES) {
      ++i;
      Thread.sleep(SHORT_TIMEOUT_MILLISECONDS);
    }

    Assert.assertTrue("Failed to connect to the server", s.isConnected()
        && i < RETRY_TIMES);

    int b = s.getInputStream().read();
    Assert.assertTrue("The server failed to disconnect", b == -1);
  } finally {
    s.close();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:TestPortmap.java

示例5: NetworkConnection

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Creates a connection using a connected socket
 *
 * @param socket the socket this connection is based on
 * @throws IOException if the socket is either closed, unbound or not connected.
 */
public NetworkConnection(Socket socket) throws IOException {
    if (socket.isClosed() || !socket.isBound() || !socket.isConnected())
        throw new IOException("NetworkConnection expects a not closed, bound and connected socket");

    this.socket = socket;
}
 
开发者ID:MatzeS,项目名称:blackbird,代码行数:13,代码来源:NetworkConnection.java

示例6: Client

import java.net.Socket; //导入方法依赖的package包/类
public Client(final String ip, int port) throws UnknownHostException,
		IOException, ClassNotFoundException {
	Socket socket = new Socket(ip, port);
	ObjectOutputStream outToClient = new ObjectOutputStream(
			socket.getOutputStream());
	ObjectInputStream inFromClient = new ObjectInputStream(
			socket.getInputStream());

	long startTime = System.currentTimeMillis();
	long currentTime = System.currentTimeMillis();
	while (socket.isConnected() && jobs < MAX_JOBS
			&& (currentTime - startTime) < MAX_RUNTIME) {
		jobs++;
		ResultRunnable job = (ResultRunnable) inFromClient.readObject();
		job.setIPAdress(ip);
		job.run();
		Object result = job.getResult();
		try {
			outToClient.writeObject(result);
		} catch (NotSerializableException e) {
			outToClient.writeObject(e);
		}
		currentTime = System.currentTimeMillis();
	}

	if (!socket.isClosed()) {
		restart = true;
	}

	socket.close();
}
 
开发者ID:NeoRoy,项目名称:KeYExperienceReport,代码行数:32,代码来源:Client.java

示例7: getAlgorithmConstraints

import java.net.Socket; //导入方法依赖的package包/类
private AlgorithmConstraints getAlgorithmConstraints(Socket socket) {
    if (socket != null && socket.isConnected() &&
                                    socket instanceof SSLSocket) {

        SSLSocket sslSocket = (SSLSocket)socket;
        SSLSession session = sslSocket.getHandshakeSession();

        if (session != null) {
            ProtocolVersion protocolVersion =
                ProtocolVersion.valueOf(session.getProtocol());
            if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
                String[] peerSupportedSignAlgs = null;

                if (session instanceof ExtendedSSLSession) {
                    ExtendedSSLSession extSession =
                        (ExtendedSSLSession)session;
                    peerSupportedSignAlgs =
                        extSession.getPeerSupportedSignatureAlgorithms();
                }

                return new SSLAlgorithmConstraints(
                    sslSocket, peerSupportedSignAlgs, true);
            }
        }

        return new SSLAlgorithmConstraints(sslSocket, true);
    }

    return new SSLAlgorithmConstraints((SSLSocket)null, true);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:X509KeyManagerImpl.java

示例8: getRequestedServerNames

import java.net.Socket; //导入方法依赖的package包/类
static List<SNIServerName> getRequestedServerNames(Socket socket) {
    if (socket != null && socket.isConnected() &&
                                    socket instanceof SSLSocket) {

        SSLSocket sslSocket = (SSLSocket)socket;
        SSLSession session = sslSocket.getHandshakeSession();

        if (session != null && (session instanceof ExtendedSSLSession)) {
            ExtendedSSLSession extSession = (ExtendedSSLSession)session;
            return extSession.getRequestedServerNames();
        }
    }

    return Collections.<SNIServerName>emptyList();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:X509TrustManagerImpl.java

示例9: testPortOpen

import java.net.Socket; //导入方法依赖的package包/类
public static void testPortOpen() throws Exception {
    ChatServer server = startServer();
    try {
        Socket socket = new Socket("localhost", listeningPort);
        if (!socket.isConnected()) {
            throw new RuntimeException("Failed to connect to server: port not open");
        }
    } finally {
        server.shutdown();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:ChatTest.java

示例10: getAlgorithmConstraints

import java.net.Socket; //导入方法依赖的package包/类
private AlgorithmConstraints getAlgorithmConstraints(Socket socket) {
    if (socket != null && socket.isConnected() &&
                                    socket instanceof SSLSocket) {

        SSLSocket sslSocket = (SSLSocket)socket;
        SSLSession session = sslSocket.getHandshakeSession();

        if (session != null) {
            ProtocolVersion protocolVersion =
                ProtocolVersion.valueOf(session.getProtocol());
            if (protocolVersion.useTLS12PlusSpec()) {
                String[] peerSupportedSignAlgs = null;

                if (session instanceof ExtendedSSLSession) {
                    ExtendedSSLSession extSession =
                        (ExtendedSSLSession)session;
                    peerSupportedSignAlgs =
                        extSession.getPeerSupportedSignatureAlgorithms();
                }

                return new SSLAlgorithmConstraints(
                    sslSocket, peerSupportedSignAlgs, true);
            }
        }

        return new SSLAlgorithmConstraints(sslSocket, true);
    }

    return new SSLAlgorithmConstraints((SSLSocket)null, true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:X509KeyManagerImpl.java

示例11: closeSocket

import java.net.Socket; //导入方法依赖的package包/类
public static void closeSocket(Socket socket) {
	if (socket != null) {
		if (socket.isConnected()) {
			try {
				socket.close();
			} catch (IOException e) {
				DLog.e(e);
			}
		}
	}
}
 
开发者ID:youmi,项目名称:nativead,代码行数:12,代码来源:IOUtils.java

示例12: checkAdditionalTrust

import java.net.Socket; //导入方法依赖的package包/类
private void checkAdditionalTrust(X509Certificate[] chain, String authType,
            Socket socket, boolean isClient) throws CertificateException {
    if (socket != null && socket.isConnected() &&
                                socket instanceof SSLSocket) {

        SSLSocket sslSocket = (SSLSocket)socket;
        SSLSession session = sslSocket.getHandshakeSession();
        if (session == null) {
            throw new CertificateException("No handshake session");
        }

        // check endpoint identity
        String identityAlg = sslSocket.getSSLParameters().
                                    getEndpointIdentificationAlgorithm();
        if (identityAlg != null && identityAlg.length() != 0) {
            String hostname = session.getPeerHost();
            X509TrustManagerImpl.checkIdentity(
                                hostname, chain[0], identityAlg);
        }

        // try the best to check the algorithm constraints
        ProtocolVersion protocolVersion =
            ProtocolVersion.valueOf(session.getProtocol());
        AlgorithmConstraints constraints = null;
        if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
            if (session instanceof ExtendedSSLSession) {
                ExtendedSSLSession extSession =
                                (ExtendedSSLSession)session;
                String[] peerSupportedSignAlgs =
                        extSession.getLocalSupportedSignatureAlgorithms();

                constraints = new SSLAlgorithmConstraints(
                                sslSocket, peerSupportedSignAlgs, true);
            } else {
                constraints =
                        new SSLAlgorithmConstraints(sslSocket, true);
            }
        } else {
            constraints = new SSLAlgorithmConstraints(sslSocket, true);
        }

        checkAlgorithmConstraints(chain, constraints);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:SSLContextImpl.java

示例13: checkTrusted

import java.net.Socket; //导入方法依赖的package包/类
private void checkTrusted(X509Certificate[] chain, String authType,
            Socket socket, boolean isClient) throws CertificateException {
    Validator v = checkTrustedInit(chain, authType, isClient);

    AlgorithmConstraints constraints = null;
    if ((socket != null) && socket.isConnected() &&
                                    (socket instanceof SSLSocket)) {

        SSLSocket sslSocket = (SSLSocket)socket;
        SSLSession session = sslSocket.getHandshakeSession();
        if (session == null) {
            throw new CertificateException("No handshake session");
        }

        // check endpoint identity
        String identityAlg = sslSocket.getSSLParameters().
                                    getEndpointIdentificationAlgorithm();
        if (identityAlg != null && identityAlg.length() != 0) {
            checkIdentity(session, chain[0], identityAlg, isClient,
                    getRequestedServerNames(socket));
        }

        // create the algorithm constraints
        ProtocolVersion protocolVersion =
            ProtocolVersion.valueOf(session.getProtocol());
        if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
            if (session instanceof ExtendedSSLSession) {
                ExtendedSSLSession extSession =
                                (ExtendedSSLSession)session;
                String[] localSupportedSignAlgs =
                        extSession.getLocalSupportedSignatureAlgorithms();

                constraints = new SSLAlgorithmConstraints(
                                sslSocket, localSupportedSignAlgs, false);
            } else {
                constraints =
                        new SSLAlgorithmConstraints(sslSocket, false);
            }
        } else {
            constraints = new SSLAlgorithmConstraints(sslSocket, false);
        }
    }

    X509Certificate[] trustedChain = null;
    if (isClient) {
        trustedChain = validate(v, chain, constraints, null);
    } else {
        trustedChain = validate(v, chain, constraints, authType);
    }
    if (debug != null && Debug.isOn("trustmanager")) {
        System.out.println("Found trusted certificate:");
        System.out.println(trustedChain[trustedChain.length - 1]);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:55,代码来源:X509TrustManagerImpl.java

示例14: checkTrusted

import java.net.Socket; //导入方法依赖的package包/类
private void checkTrusted(X509Certificate[] chain, String authType,
            Socket socket, boolean isClient) throws CertificateException {
    Validator v = checkTrustedInit(chain, authType, isClient);

    X509Certificate[] trustedChain = null;
    if ((socket != null) && socket.isConnected() &&
                                    (socket instanceof SSLSocket)) {

        SSLSocket sslSocket = (SSLSocket)socket;
        SSLSession session = sslSocket.getHandshakeSession();
        if (session == null) {
            throw new CertificateException("No handshake session");
        }

        // create the algorithm constraints
        ProtocolVersion protocolVersion =
            ProtocolVersion.valueOf(session.getProtocol());
        boolean isExtSession = (session instanceof ExtendedSSLSession);
        AlgorithmConstraints constraints = null;
        if (protocolVersion.v >= ProtocolVersion.TLS12.v && isExtSession) {
            ExtendedSSLSession extSession = (ExtendedSSLSession)session;
            String[] localSupportedSignAlgs =
                    extSession.getLocalSupportedSignatureAlgorithms();

            constraints = new SSLAlgorithmConstraints(
                            sslSocket, localSupportedSignAlgs, false);
        } else {
            constraints = new SSLAlgorithmConstraints(sslSocket, false);
        }

        // Grab any stapled OCSP responses for use in validation
        List<byte[]> responseList = Collections.emptyList();
        if (!isClient && isExtSession) {
            responseList =
                    ((ExtendedSSLSession)session).getStatusResponses();
        }
        trustedChain = validate(v, chain, responseList,
                constraints, isClient ? null : authType);

        // check if EE certificate chains to a public root CA (as
        // pre-installed in cacerts)
        boolean chainsToPublicCA =
            AnchorCertificates.contains(trustedChain[trustedChain.length-1]);

        // check endpoint identity
        String identityAlg = sslSocket.getSSLParameters().
                getEndpointIdentificationAlgorithm();
        if (identityAlg != null && identityAlg.length() != 0) {
            checkIdentity(session, trustedChain[0], identityAlg, isClient,
                    getRequestedServerNames(socket), chainsToPublicCA);
        }
    } else {
        trustedChain = validate(v, chain, Collections.emptyList(),
                null, isClient ? null : authType);
    }
    if (debug != null && Debug.isOn("trustmanager")) {
        System.out.println("Found trusted certificate:");
        System.out.println(trustedChain[trustedChain.length - 1]);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:X509TrustManagerImpl.java

示例15: isSocketConnected

import java.net.Socket; //导入方法依赖的package包/类
private boolean isSocketConnected(Socket socket) {
  return socket.isConnected();
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:4,代码来源:SocketInternetObservingStrategy.java


注:本文中的java.net.Socket.isConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。