Socket setSoLinger Example

Started by VelMurugan, Jan 02, 2009, 07:09 AM

Previous topic - Next topic

VelMurugan

Socket setSoLinger Example

Socket class setSoLinger example. This example shows you how to use setSoLinger method.

Socket class setSoLinger example. public void setSoLinger(boolean , int) throws SocketException Enable/disable SO_LINGER with the specified linger time in seconds. The maximum timeout value is platform specific. The setting only affects socket close.

/*
* @ # SetSoLinger.java
* A class repersenting use to SetSoLinger method
* of Socket class in java.net package
* version 17 June 2008
* author Rose India
*/

import java.net.*;

public class SetSoLinger {

    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.222", 8080));

        System.out.println("SO_LINGER " + socket.getSoLinger());
        socket.setSoLinger(true, 1);
        System.out.println("SO_LINGER " + socket.getSoLinger());
        socket.close();
    }
}


Output
Quote
SO_LINGER -1
SO_LINGER 1

Source : codingdiary