Home Java Network GetKeepAlive
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

GetKeepAlive

Advertisement
In this section, you will show the used of several method for different output massage. Here, we provide a complete example based on the method for creating the Socket() method. Firstly create a class named of "getKeepAlive" and initialize a class Socket

GetKeepAlive

     

In this section, you will show the used of several method for different output massage. Here, we provide a complete example based on the method for creating the Socket() method. Firstly create a class named of  "getKeepAlive" and initialize a class Socket. The main purpose of the server socket is to listen an incoming connection request and ordinary socket is used to ask to server for the connection. Here, we are going to explain the method to find out the local address of local system. This is the program also represent the several information about the server socket. 

Code Description:

getKeepAlive():
This is the method returns a boolean indicating whether or not SO_KEEPALIVE is enabled.

getSendBufferSize():
This method gets the value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.

isOutputShutdown():
This method returns whether the write-half of the socket connection is closed. This method returns true if the output of the socket has been shutdown.

getPort(): This method returns the port number of local  machine.

getLocalSocketAddress(): This is the method returns the address of the endpoint this socket.

Here is the code of  this program:

import java.net.*;
import java.io.*;

public class getKeepAlive{
  public static final short TIME_PORT = 135;
  public static void main(String[] args) throws IOException{
    String hostName = null;
    System.out.println();
    try{
      Socket socket= new Socket(hostName,TIME_PORT);
      System.out.println("socket =" + socket);
      System.out.println("Keep Alive="+ socket.getKeepAlive());
      System.out.println("Send Buffer size ="+ socket.getSendBufferSize());
      System.out.println("output ="+socket.isOutputShutdown());
      System.out.println("port is =" + socket.getPort());
      System.out.println("socket address ="+socket.getLocalSocketAddress());
      InetAddress in= socket.getInetAddress();
      System.out.println(in);
      System.out.println("\n");
      System.out.print("RAW IP Address - (byte[]) : ");
      byte[] b1 = in.getAddress();
      for (int i=0; i< b1.length; i++) {
        if (i > 0) {
          System.out.print(".");}
          System.out.print(b1[i]);
      }

    }
    catch (UnknownHostException  e)  {
      e.printStackTrace();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}



Output of  this program:

 C:\rose>java getKeepAlive

socket =Socket[addr=localhost/127.0.0.1,port=135,localport=1302]
Keep Alive=false
Send Buffer size =8192
output =false
port is =135
socket address =/127.0.0.1:1302
localhost/127.0.0.1

RAW IP Address - (byte[]) : 127.0.0.1
C:\rose>

 

Download of this program.

 

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 19, 2008

Ask Questions?    Discuss: GetKeepAlive  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com