List of usage examples for java.net Socket setSoTimeout
public synchronized void setSoTimeout(int timeout) throws SocketException
From source file:org.xapek.zs.InsecureSSLProtocolSocketFactory.java
/** * {@inheritDoc}// ww w. ja va 2 s . co m */ public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort) throws IOException { Socket createSocket = context_.getSocketFactory().createSocket(host, port, localAddress, localPort); createSocket.setSoTimeout(1); return createSocket; }
From source file:org.xapek.zs.InsecureSSLProtocolSocketFactory.java
/** * {@inheritDoc}/*from w ww .j a v a 2 s . c o m*/ */ public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException { Socket createSocket = context_.getSocketFactory().createSocket(host, port, localAddress, localPort); createSocket.setSoTimeout(1); return createSocket; }
From source file:org.jzkit.z3950.server.Z3950Listener.java
public void run() { try {/*from ww w .ja va 2 s . c o m*/ log.debug("Starting ZServer on port " + port + " (timeout=" + socket_timeout + ")"); server_socket = new ServerSocket(port); while (running) { log.debug("Waiting for connection"); Socket socket = (Socket) server_socket.accept(); socket.setSoTimeout(socket_timeout); // AppCtx config will determine if this object is a singleton or per assoc... log.debug("Obtaining handle to backend and creating association"); Z3950NonBlockingBackend backend = (Z3950NonBlockingBackend) ctx.getBean(backend_bean_name); log.debug("new backend instance " + backend.hashCode()); ZServerAssociation za = new ZServerAssociation(socket, backend, ctx); } server_socket.close(); } catch (IOException e) { log.error("Problem", e); } }
From source file:pl.edu.agh.ServiceConnection.java
/** * 1. Sends data to service: console password | service password | service id *//* ww w. jav a 2s . c om*/ public void connect(Service service) { try { LOGGER.info("Connecting to service: " + service); Socket socket = new Socket(service.getHost(), service.getPort()); socket.setSoTimeout(300); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out.writeBytes(service.getPassword() + "|" + service.getId() + "\r\n"); String response = in.readLine(); in.close(); out.close(); socket.close(); LOGGER.info("Service response: " + response); } catch (Exception e) { LOGGER.error("Error connecting with daemon: " + e.getMessage()); } }
From source file:org.hashes.HttpClient.java
protected void applySettings(final Socket socket) throws SocketException { socket.setTcpNoDelay(true);// w w w . j a va 2 s . co m socket.setSoTimeout(this.target.getReadTimeout()); }
From source file:org.workin.fastdfs.factory.DefaultPoolableTrackerServerFactory.java
@Override public void activateObject(TrackerServer trackerServer) throws Exception { Socket socket = trackerServer.getSocket(); if (!socket.isConnected() || socket.isClosed()) { /* ?TrackerServer */ socket.setSoTimeout(ClientGlobal.g_network_timeout); socket.connect(trackerServer.getInetSocketAddress(), ClientGlobal.g_connect_timeout); }/*from w ww . j a v a2 s. com*/ }
From source file:com.nmote.smpp.TCPLinkFactory.java
protected Socket createSocket() throws IOException { if (host == null) { throw new IOException("Remote host not specified"); }/* w w w . ja va 2 s. c o m*/ Socket result = new Socket(host, port); if (timeout != 0) { result.setSoTimeout(timeout); } return result; }
From source file:org.apache.batchee.cli.command.SocketCommand.java
protected void sendCommand() { if (adminSocket < 0) { throw new BatchContainerRuntimeException("specify -socket to be able to run this command"); }/*from w ww . jav a 2 s .c o m*/ Socket socket = null; try { socket = new Socket("localhost", adminSocket); socket.setSoTimeout(timeout); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Integer> answer = new AtomicReference<Integer>(); new AnswerThread(socket, answer, latch).start(); final OutputStream outputStream = socket.getOutputStream(); outputStream.write(command().getBytes()); outputStream.flush(); socket.shutdownOutput(); try { latch.await(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { info("no answer after " + timeout + "ms"); return; } if (answer.get() != 0) { info("unexpected answer: " + answer.get()); } } catch (final IOException e) { throw new BatchContainerRuntimeException(e); } finally { IOUtils.closeQuietly(socket); } }
From source file:com.googlecode.jcimd.DummyCimdServer.java
public void start() throws IOException { this.serverSocket = new ServerSocket(this.port); if (this.logger.isInfoEnabled()) { this.logger.info("Listening on port " + this.port); }//from w w w .j a v a 2 s .co m Runnable listener = new Runnable() { @Override public void run() { try { while (!Thread.currentThread().isInterrupted()) { try { Socket socket = serverSocket.accept(); socket.setSoTimeout(2000); if (logger.isInfoEnabled()) { logger.info("Starting session with " + socket.getInetAddress().getHostAddress() + ":" + socket.hashCode()); } DummyCimdServer.Session session = new Session(socket); //List<Session> sessions = ...; //sessions.add(session); new Thread(session).start(); } catch (SocketException e) { // Ignore, as this was due to #stop } } } catch (IOException e) { throw new RuntimeException(e); } } }; this.thread = new Thread(listener, this.getClass().getName() + "-listener"); this.thread.start(); }
From source file:com.tasktop.c2c.server.web.proxy.ajp.AjpPoolableConnectionFactory.java
@Override public Object makeObject(Object objectKey) throws Exception { Key key = (Key) objectKey; String host = key.getHost();/*from ww w. j av a 2 s . c om*/ int port = key.getPort(); if (port <= 0) { port = 8009; } Socket socket = socketFactory.createSocket(host, port); try { socket.setTcpNoDelay(tcpNoDelay); socket.setSoTimeout(soTimeout); socket.setKeepAlive(keepAlive); } catch (SocketException e) { socket.close(); throw e; } debug("Created new socket: " + socket.toString()); return socket; }