ServerSocket SetSoTimeout() Example

Started by VelMurugan, Jan 05, 2009, 11:09 PM

Previous topic - Next topic

VelMurugan

ServerSocket SetSoTimeout() Example

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

ServerSocketclass SetSoTimeout() method example. This example shows you how to use SetSoTimeout() method.This method Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

Here is the code:-


/**
* @Program that Enable/disable SO_TIMEOUT with the specified timeout
* SetSoTimeout.java
* Author:-RoseIndia Team
* Date:-21-jun-2008
*/
import java.net.*;

public class SetSoTimeout {

    public static void main(String[] args) throws Exception {
        InetAddress i = InetAddress.getByName("girish-desktop");
        ServerSocket ss = new ServerSocket(8080, 1, i);
        //Returns the binding state of the ServerSocket.
        System.out.println("Setting for SO_TIMEOUT is: " + ss.getSoTimeout());
        //Enable/disable SO_TIMEOUT with the specified timeout
        ss.setSoTimeout(2048);
        System.out.println("Setting for SO_TIMEOUT is: " + ss.getSoTimeout());
    }
}


Output of the program:-

Setting for SO_TIMEOUT is: 0
Setting for SO_TIMEOUT is: 2048

Source : codingdiary