List of usage examples for java.net Socket isInputShutdown
public boolean isInputShutdown()
From source file:Main.java
public static void main(String[] args) throws Exception { Socket client = new Socket("google.com", 80); System.out.println(client.isInputShutdown()); client.close();//from w w w . j a v a2 s. com }
From source file:com.sharneng.net.NetUtils.java
/** * Quietly shutdown the input of a {@linkplain Socket}. Exception are ignored. * //www.ja v a 2 s . c o m * @param socket * the socket to shutdown the input */ public static void shutdownInput(Socket socket) { if (socket == null) return; try { if (!socket.isInputShutdown()) socket.shutdownInput(); } catch (Throwable e) { log.debug(e.getMessage(), e); } }
From source file:com.googlecode.jmxtrans.connections.SocketFactory.java
/** * Validates that the socket is good./* w ww . j ava 2 s. c o m*/ */ @Override public boolean validateObject(InetSocketAddress address, Socket socket) { if (socket == null) { log.error("Socket is null [{}]", address); return false; } if (!socket.isBound()) { log.error("Socket is not bound [{}]", address); return false; } if (socket.isClosed()) { log.error("Socket is closed [{}]", address); return false; } if (!socket.isConnected()) { log.error("Socket is not connected [{}]", address); return false; } if (socket.isInputShutdown()) { log.error("Socket input is shutdown [{}]", address); return false; } if (socket.isOutputShutdown()) { log.error("Socket output is shutdown [{}]", address); return false; } return true; }
From source file:com.symbian.driver.core.controller.tasks.TEFTask.java
/** * @param aVisitor// w w w .j av a 2 s. c om * @param aTestExecuteScript * @param lExecuteOnDevice * @param aTask * @return The last execption raised when running UCC. * @throws JStatException */ private boolean runUCC(List<String> aArgs, Task aTask) { boolean lReturn = true; Socket lUccSocket = null; DataOutputStream lSocketOut = null; DataInputStream lSocketIn = null; int lRunNumber = 0; int lUccPort = -1; String lUccAddress = null; IDeviceComms.ISymbianProcess lProcess = null; try { String[] lUccSplit = TDConfig.getInstance().getPreference(TDConfig.UCC_IP_ADDRESS).split(":"); lRunNumber = TDConfig.getInstance().getPreferenceInteger(TDConfig.RUN_NUMBER); lUccAddress = lUccSplit[0]; lUccPort = Integer.parseInt(lUccSplit[1]); } catch (ParseException lParseException) { LOGGER.log(Level.SEVERE, "Could not get configuration for UCC.", lParseException); iExceptions.put(lParseException, ESeverity.ERROR); lReturn = false; } catch (NumberFormatException lNumberFormatException) { LOGGER.log(Level.SEVERE, "Could not parse the port number for UCC.", lNumberFormatException); iExceptions.put(lNumberFormatException, ESeverity.ERROR); lReturn = false; } if (lUccAddress == null || lUccAddress.equals("") || lUccPort < 0) { iExceptions.put( new UnknownHostException("Please specify a valid UCC address for example 192.168.0.1:3000"), ESeverity.ERROR); return false; } // Run the test try { LOGGER.info("Running UCC with:\n\tAddress: " + lUccAddress + "\n\tUCC Port:" + lUccPort); lUccSocket = new Socket(lUccAddress, lUccPort); lSocketOut = new DataOutputStream(lUccSocket.getOutputStream()); lSocketIn = new DataInputStream(lUccSocket.getInputStream()); LOGGER.fine("Starting UCC while still polling"); lProcess = iDeviceProxy.createSymbianProcess(); if (lProcess != null) { // run and don't wait if (!lProcess.runCommand(TEST_EXECUTE, aArgs, aTask.getTimeout() * 1000, false)) { iExceptions.put(new Exception("Failed to run TEF for UCC."), ESeverity.ERROR); lReturn = false; } // Tell UCC that the test has started. LOGGER.fine("Writing to UCC socket: " + lRunNumber); lSocketOut.writeInt(lRunNumber); lSocketOut.flush(); int lUCCReply = lSocketIn.readInt(); LOGGER.fine("UCC Reply: " + lUCCReply); } } catch (UnknownHostException lUnknownHostException) { LOGGER.log(Level.SEVERE, "Could not find UCC host", lUnknownHostException); iExceptions.put(lUnknownHostException, ESeverity.ERROR); return false; } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "IO Exception during UCC testing: " + lIOException.getMessage() + (lUccSocket != null ? "\nUcc Socket Connected: " + lUccSocket.isConnected() + "\nUcc Socket InputShutdown: " + lUccSocket.isInputShutdown() + "\nUcc Socket OutputShutdown:" + lUccSocket.isOutputShutdown() + "\nUcc Socket Bound: " + lUccSocket.isBound() : "\nUcc Socket is NULL"), lIOException); iExceptions.put(lIOException, ESeverity.ERROR); return false; } finally { // Close UCC if (lSocketOut != null) { try { LOGGER.log(Level.FINE, "Closing Socket Out."); lUccSocket.shutdownInput(); lUccSocket.shutdownOutput(); lSocketOut.close(); } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "Could not close UCC Out socket.", lIOException); iExceptions.put(lIOException, ESeverity.ERROR); } } if (lSocketIn != null) { try { LOGGER.log(Level.FINE, "Closing Socket In."); lSocketIn.close(); } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "Could not close UCC In socket.", lIOException); iExceptions.put(lIOException, ESeverity.ERROR); } } if (lUccSocket != null) { try { LOGGER.log(Level.FINE, "Closing Socket UCC."); lUccSocket.close(); } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "Could not close UCC socket.", lIOException); iExceptions.put(lIOException, ESeverity.ERROR); } } if (!lUccSocket.isClosed()) { LOGGER.warning("Could not close the UCC sockets properly."); } lSocketOut = null; lSocketIn = null; lUccSocket = null; // Poll TEF Test if (!lProcess.join()) { iExceptions.put(new Exception("Coud not join UCC-TEF Process"), ESeverity.ERROR); lReturn = false; } } return lReturn; }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String RegisterTheDevice(String sSrvr, String sPort, String sData) { String sRet = ""; String line = ""; // Debug.waitForDebugger(); if (sSrvr != null && sPort != null && sData != null) { try {/* w w w. ja v a 2s . com*/ int nPort = Integer.parseInt(sPort); Socket socket = new Socket(sSrvr, nPort); PrintWriter out = new PrintWriter(socket.getOutputStream(), false); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out.println(sData); if (out.checkError() == false) { socket.setSoTimeout(30000); while (socket.isInputShutdown() == false) { line = in.readLine(); if (line != null) { line = line.toLowerCase(); sRet += line; // ok means we're done if (line.contains("ok")) break; } else { // end of stream reached break; } } } out.close(); in.close(); socket.close(); } catch (NumberFormatException e) { sRet += "reg NumberFormatException thrown [" + e.getLocalizedMessage() + "]"; e.printStackTrace(); } catch (UnknownHostException e) { sRet += "reg UnknownHostException thrown [" + e.getLocalizedMessage() + "]"; e.printStackTrace(); } catch (IOException e) { sRet += "reg IOException thrown [" + e.getLocalizedMessage() + "]"; e.printStackTrace(); } } return (sRet); }
From source file:org.apache.jmeter.visualizers.backend.graphite.SocketOutputStreamPoolFactory.java
/** *//*from w w w . j a v a 2 s . c o m*/ @Override public boolean validateObject(SocketConnectionInfos hostAndPort, PooledObject<SocketOutputStream> socketOutputStream) { Socket socket = socketOutputStream.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
From source file:org.jmxtrans.embedded.util.pool.SocketOutputStreamPoolFactory.java
/** * Defensive approach: we test all the "<code>Socket.isXXX()</code>" flags. *///w w w . ja va 2s. c o m @Override public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketOutputStream> socketOutputStreamRef) { Socket socket = socketOutputStreamRef.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
From source file:org.jmxtrans.embedded.util.pool.SocketWriterPoolFactory.java
/** * Defensive approach: we test all the "<code>Socket.isXXX()</code>" flags. *//*from w w w. ja v a2 s. c o m*/ @Override public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketWriter> socketWriterRef) { Socket socket = socketWriterRef.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }