Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSendUrgentDataExample3 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //isConnected() method returns the connected state of the socket System.out.println("The socket is connected: "+socket.isConnected()); //closing the socket if (socket.isConnected()) { int data = 0; //sendUrgentData() method sends one byte of urgent data on the socket. socket.sendUrgentData(data); //it will throw an SocketException, as the socket is not connected System.out.println("Data has been send successfully..."); } else{ System.out.println("Socket is not connected..."); System.out.println("Please connect the socket with a valid socket address and port number"); } } }
Output