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
SO_LINGER -1
SO_LINGER 1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US