Socket close Example
Socket class close example. This example shows you how to use close method.
Socket class close example. public void close() throws IOException Closes this socket. Any thread currently blocked in an I/O operation upon this socket will throw a SocketException. Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created.
Here is the code
/*
* @ # Close.java
* A class repersenting use to close method
* of Socket class in java.net package
* version 19 June 2008
* author Rose India
*/
import java.net.*;
public class Close {
public static void main(String args[]) throws Exception {
Socket socket = new Socket();
//Connects this socket to the server.
socket.connect(new InetSocketAddress("192.168.10.80", 9090));
//return getInetAddress
InetAddress inetaddress = socket.getInetAddress();
System.out.println("Inet Address is " + inetaddress);
//close socket
socket.close();
}
} |
Output
| Inet Address is /192.168.10.80 |
|