Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketShutdownOutputExample1 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); InetAddress inetAddress=InetAddress.getByName("localhost"); //the port should be greater or equal to 0, else it will throw an error int port=1085; //calling the constructor of the SocketAddress class SocketAddress socketAddress=new InetSocketAddress(inetAddress, port); //binding the socket with inetAddress and port socket.bind(socketAddress); //the connection will not establish without binding the socket with bind() method socket.connect(socketAddress); //shutdownOutput() method disables the output stream for the specified socket. socket.shutdownOutput(); //isConnected() method returns the connected state of the socket System.out.println("The socket is connected: "+socket.isConnected()); //isBound() method returns the binding state of the socket System.out.println("The socket is bounded: "+socket.isBound()); //isOutputShutdown() returns a boolean value ?true? if the write-half of the socket connection has been closed System.out.println("The socket is shutdown: "+socket.isOutputShutdown()); } }
Output