Java Socket sendUrgentData() method

The sendUrgentData() method of Java Socket class sends one byte of urgent data on the socket. The byte should be the lowest eight bits of the data parameter.

Syntax

Parameter

The ?data? parameter represents the byte of data to send.

Return

NA

Throws

IOException - if there is an error while sending the data.

Example 1

Test it Now

Output:

The socket is connected: true
Data has been sent successfully...

Example 2

Test it Now

Output:

Exception in thread "main" java.io.IOException: Socket Closed
The socket is connected: true
	at java.net.AbstractPlainSocketImpl.sendUrgentData(AbstractPlainSocketImpl.java:591)
	at java.net.PlainSocketImpl.sendUrgentData(PlainSocketImpl.java:262)
	at java.net.Socket.sendUrgentData(Socket.java:1067)
	at com.javaTpoint.JavaSocketSendUrgentDataExample2.main(JavaSocketSendUrgentDataExample2.java:23)

Example 3

Test it Now

Output:

The socket is connected: false
Socket is not connected...
Please connect the socket with a valid socket address and port number




Latest Courses