Socket setKeepAlive Example

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


Socket class setKeepAlive example. blic void setKeepAlive(boolean on) throws SocketException Enable/disable SO_KEEPALIVE.

Here is the code
/*
 * @ # SetKeepAlive.java
 * A class repersenting use to SetKeepAlive method 
 * of NumberFormat class in java.net package
 * version 17 June 2008
 * author Rose India 
 */

import java.net.*;

public class SetKeepAlive {

    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));

        if (!socket.getKeepAlive()) {
            socket.setKeepAlive(true);
        }
        System.out.println("SO_KEEPALIVE is enabled. " + socket.getKeepAlive());

        socket.close();
    }
}

Output
SO_KEEPALIVE is enabled. true

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

HOME | COPYRIGHT | CONTACT US