ServerSocket Close() Example

Started by VelMurugan, Jan 06, 2009, 08:05 AM

Previous topic - Next topic

VelMurugan

ServerSocket Close() Example

Closes this socket.

ServerSocketclass Close() method example. This example shows you how to use Close() method.This method Closes this socket.

Here is the code:-

/**
* @Program that Closes this socket.
* Close.java
* Author:-RoseIndia Team
* Date:-21-jun-2008
*/
import java.net.*;

public class Close {

    public static void main(String[] args) throws Exception{
        InetAddress i = InetAddress.getByName("girish-desktop");
        ServerSocket ss = new ServerSocket(8080, 1, i);
        System.out.println("RCVBUF option for this ServerSocket is: "
                +ss.getReceiveBufferSize());
        //Closes this socket.
        ss.close();
        System.out.println("RCVBUF option for this ServerSocket is: "
                +ss.getReceiveBufferSize());
       
    }
}


Output of the program:-

RCVBUF option for this ServerSocket is: 43690
Exception in thread "main" java.net.SocketException: Socket is closed
        at java.net.ServerSocket.getReceiveBufferSize(ServerSocket.java:763)
        at Close.main(Close.java:19)

source : codingdiary