Here you can find the source of isSocketReadyToWrite(Socket socket)
Parameter | Description |
---|---|
socket | socket to test |
Parameter | Description |
---|---|
IOException | an exception |
public static boolean isSocketReadyToWrite(Socket socket) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.OutputStream; import java.net.Socket; import java.net.SocketException; public class Main { /**//from w ww. jav a2 s . com * Determines if the socket can be written to. This method tests the writability of the socket by writing to the socket, * so it should only be used immediately before closing the socket. * * @param socket socket to test * @return true if the socket is open and can be written to, otherwise false * @throws IOException */ public static boolean isSocketReadyToWrite(Socket socket) throws IOException { OutputStream out = socket.getOutputStream(); try { out.write(0); out.flush(); out.write(0); out.flush(); } catch (SocketException e) { return false; } return true; } }