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


Java Socket.isClosed方法代码示例

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


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

示例1: isSecure

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Checks whether a socket connection is secure.
 * This factory creates TLS/SSL socket connections
 * which, by default, are considered secure.
 * <br/>
 * Derived classes may override this method to perform
 * runtime checks, for example based on the cypher suite.
 *
 * @param sock the connected socket
 * @return <code>true</code>
 * @throws IllegalArgumentException if the argument is invalid
 */
public boolean isSecure(final Socket sock) throws IllegalArgumentException
{
	if (sock == null)
	{
		throw new IllegalArgumentException("Socket may not be null");
	}

	// This instanceof check is in line with createSocket() above.
	if (!(sock instanceof SSLSocket))
	{
		throw new IllegalArgumentException("Socket not created by this factory");
	}

	// This check is performed last since it calls the argument object.
	if (sock.isClosed())
	{
		throw new IllegalArgumentException("Socket is closed");
	}

	return true;
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:34,代码来源:SSLSocketFactory.java

示例2: run

import java.net.Socket; //导入方法依赖的package包/类
public void run() {
		while(!server.isClosed()){
				Socket sk = null;
				try {
					sk = server.accept();
				} catch (IOException e) {
					// TODO Auto-generated catch block
e.printStackTrace();logger.error("Exception",e);
				}
				if(sk!=null&&!sk.isClosed()){
					NodeReceiveThread nrt= new NodeReceiveThread(sk);
					nrt.start();
				}	
		}
		System.out.println("server closed");	
		logger.info("server closed");
	}
 
开发者ID:zrtzrt,项目名称:CrawlerSYS,代码行数:18,代码来源:CrawlerServer.java

示例3: isSecure

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Checks whether a socket connection is secure.
 * This factory creates plain socket connections
 * which are not considered secure.
 *
 * @param sock      the connected socket
 *
 * @return  <code>false</code>
 *
 * @throws IllegalArgumentException if the argument is invalid
 */
public final boolean isSecure(Socket sock)
    throws IllegalArgumentException {

    if (sock == null) {
        throw new IllegalArgumentException("Socket may not be null.");
    }
    // This class check assumes that createSocket() calls the constructor
    // directly. If it was using javax.net.SocketFactory, we couldn't make
    // an assumption about the socket class here.
    if (sock.getClass() != Socket.class) {
        throw new IllegalArgumentException
            ("Socket not created by this factory.");
    }
    // This check is performed last since it calls a method implemented
    // by the argument object. getClass() is final in java.lang.Object.
    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed.");
    }

    return false;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:MultihomePlainSocketFactory.java

示例4: testClosedSocketCloser

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Verify that a closed SocketCloser will still close an open socket
 */
@Test
public void testClosedSocketCloser() {
  final AtomicBoolean runnableCalled = new AtomicBoolean();
  Runnable r = new Runnable() {
    @Override
    public void run() {
      runnableCalled.set(true);
    }
  };

  final Socket s = createClosableSocket();
  this.socketCloser.close();
  this.socketCloser.asyncClose(s, "A", r);
  WaitCriterion wc = new WaitCriterion() {
    public boolean done() {
      return runnableCalled.get() && s.isClosed();
    }

    public String description() {
      return "runnable was not called or socket was not closed";
    }
  };
  Wait.waitForCriterion(wc, 5000, 10, true);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:28,代码来源:SocketCloserJUnitTest.java

示例5: isSecure

import java.net.Socket; //导入方法依赖的package包/类
@Override
public boolean isSecure(Socket sock) throws IllegalArgumentException {
	if (sock == null) {
		throw new IllegalArgumentException("Socket may not be null.");
	}

	if (!(sock instanceof SSLSocket)) {
		throw new IllegalArgumentException("Socket not created by this factory.");
	}

	if (sock.isClosed()) {
		throw new IllegalArgumentException("Socket is closed.");
	}

	return true;

}
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:18,代码来源:MySSLSocketFactory.java

示例6: 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

示例7: 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

示例8: isHealthy

import java.net.Socket; //导入方法依赖的package包/类
boolean isHealthy(boolean doExtensiveChecks) {
    if (!connected) {
        return false;
    }

    Socket socket;
    BufferedSource source;
    synchronized (this) {
        socket = this.socket;
        source = this.source;
    }
    if (socket == null ||
            source == null ||
            socket.isClosed() ||
            socket.isInputShutdown() ||
            socket.isOutputShutdown()) {
        return false;
    }

    if (doExtensiveChecks) {
        try {
            int readTimeout = socket.getSoTimeout();
            try {
                socket.setSoTimeout(1);
                return !source.exhausted();
            } finally {
                socket.setSoTimeout(readTimeout);
            }
        } catch (SocketTimeoutException ignored) {
            ignored.printStackTrace();
            // Read timed out; socket is good.
        } catch (IOException e) {
            return false; // Couldn't read; socket is closed.
        }
    }

    return true;
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:39,代码来源:RealConnection.java

示例9: closeSocket

import java.net.Socket; //导入方法依赖的package包/类
private void closeSocket(Socket socket) {
    try {
        if (!socket.isClosed()) {
            socket.close();
        }
    } catch (IOException e) {
        onError(new ProxyCacheException("Error closing socket", e));
    }
}
 
开发者ID:Achenglove,项目名称:AndroidVideoCache,代码行数:10,代码来源:HttpProxyCacheServer.java

示例10: run

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void run() {
	List<Socket> sockets = new ArrayList<Socket>();
	while (this.tokenResponse == null) {
		Socket s;
		try {
			s = this.socket.accept();
			sockets.add(s);
			InternalWebServerTransaction c = new InternalWebServerTransaction(s,this, nonce.toString());
			c.addObserver(this);
		} catch (IOException e) {
			if(e instanceof SocketException) {
				// When user obtain a token closing listen socket cause this exception
				// In this case this is a normal exception
				logger.info("Closing listening socket.");
			} else {
				logger.error("IOException while accepting client requests", e);
			}
			// Close all transcation sockets
			for(Socket transactionSocket: sockets) {
				try {
					if(!transactionSocket.isClosed()) {
						transactionSocket.close();
					}
				} catch (IOException e1) {
					logger.error("IOException while closing client requests", e1);
				}
			}
			serverThread.interrupt();
		}
       }		
	serverThread.interrupt();
}
 
开发者ID:OwaNotifier,项目名称:owa-notifier,代码行数:34,代码来源:InternalWebServer.java

示例11: request

import java.net.Socket; //导入方法依赖的package包/类
public static Packet request(String host, int port, Packet packet) {
    KeyPair keyPair = Crypter.generateKeyPair();

    try {
        Socket socket = new Socket(host, port);

        if (socket.isClosed()) {
            return new ErrorPacket("socket closed");
        }

        ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
        ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

        out.writeObject(keyPair.getPublic());
        PublicKey publicKey = (PublicKey) in.readObject();

        SecretKey key = Crypter.generateEC(keyPair.getPrivate(), publicKey);

        out.writeObject(Crypter.encrypt(key, Crypter.toByteArray(packet)));
        out.flush();

        Packet response = (Packet) Crypter.toObject(Crypter.decrypt(key, (byte[]) in.readObject()));

        in.close();
        out.close();
        socket.close();

        return response;
    } catch (Exception ex) {
        return new ErrorPacket(ex.getMessage());
    }
}
 
开发者ID:NexusByte,项目名称:LotusCloud,代码行数:33,代码来源:PacketClient.java

示例12: isSecure

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Checks whether a socket connection is secure.
 * This factory creates plain socket connections
 * which are not considered secure.
 *
 * @param sock      the connected socket
 *
 * @return  <code>false</code>
 *
 * @throws IllegalArgumentException if the argument is invalid
 */
public final boolean isSecure(Socket sock)
    throws IllegalArgumentException {

    if (sock == null) {
        throw new IllegalArgumentException("Socket may not be null.");
    }
    // This check is performed last since it calls a method implemented
    // by the argument object. getClass() is final in java.lang.Object.
    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed.");
    }
    return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:PlainSocketFactory.java

示例13: isSecure

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Checks whether a socket connection is secure.
 * This factory creates TLS/SSL socket connections
 * which, by default, are considered secure.
 * <br/>
 * Derived classes may override this method to perform
 * runtime checks, for example based on the cypher suite.
 *
 * @param sock      the connected socket
 *
 * @return  <code>true</code>
 *
 * @throws IllegalArgumentException if the argument is invalid
 */
public boolean isSecure(final Socket sock) throws IllegalArgumentException {
    if (sock == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    // This instanceof check is in line with createSocket() above.
    if (!(sock instanceof SSLSocket)) {
        throw new IllegalArgumentException("Socket not created by this factory");
    }
    // This check is performed last since it calls the argument object.
    if (sock.isClosed()) {
        throw new IllegalArgumentException("Socket is closed");
    }
    return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:SSLSocketFactory.java

示例14: init

import java.net.Socket; //导入方法依赖的package包/类
private void init() throws Exception {
  try {
    socket = new Socket(targetHost, targetPort);
    outputStream = socket.getOutputStream();
    PrintWriter out = new PrintWriter(outputStream, false);
    InputStream inputStream = socket.getInputStream();

    // send an HTTP request to the web server
    out.println(String.format("SOURCE %s HTTP/1.0", mounter));
    out.println(String.format("Authorization: Basic %s", HttpRequest.Base64.encode(user + ":" + password)));
    out.println("User-Agent: libshout/2.3.1");
    out.println(String.format("Content-Type: %s", mimeType.getContentType()));
    out.println(String.format("ice-name: %s", iceName));
    out.println("ice-public: 0");
    if (iceDesc != null) {
      out.println(String.format("ice-description: %s", iceDesc));
    }
    out.println();
    out.flush();

    // check if 404
    LineReader lineReader = new LineReader(new InputStreamReader(inputStream));
    String data = lineReader.readLine();

    handleResponse(data);
  } catch (Exception e) {
    if (socket != null && !socket.isClosed()) {
      try {
        socket.close();
      } catch (IOException e1) {
        // skip
      }
    }
    throw e;
  }
}
 
开发者ID:caorong,项目名称:libshout-java,代码行数:37,代码来源:Jlibshout.java

示例15: asyncClose

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Closes the specified socket in a background thread. In some cases we see close hang (see bug
 * 33665). Depending on how the SocketCloser is configured (see ASYNC_CLOSE_WAIT_MILLISECONDS)
 * this method may block for a certain amount of time. If it is called after the SocketCloser is
 * closed then a normal synchronous close is done.
 * 
 * @param sock the socket to close
 * @param address identifies who the socket is connected to
 * @param extra an optional Runnable with stuff to execute in the async thread
 */
public void asyncClose(final Socket sock, final String address, final Runnable extra) {
  if (sock == null || sock.isClosed()) {
    return;
  }
  boolean doItInline = false;
  try {
    synchronized (asyncCloseExecutors) {
      if (isClosed()) {
        // this SocketCloser has been closed so do a synchronous, inline, close
        doItInline = true;
      } else {
        asyncExecute(address, new Runnable() {
          public void run() {
            Thread.currentThread().setName("AsyncSocketCloser for " + address);
            try {
              if (extra != null) {
                extra.run();
              }
              inlineClose(sock);
            } finally {
              Thread.currentThread().setName("unused AsyncSocketCloser");
            }
          }
        });
      }
    }
  } catch (OutOfMemoryError ignore) {
    // If we can't start a thread to close the socket just do it inline.
    // See bug 50573.
    doItInline = true;
  }
  if (doItInline) {
    if (extra != null) {
      extra.run();
    }
    inlineClose(sock);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:49,代码来源:SocketCloser.java


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