[an error occurred while processing this directive]



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:

This is the method returns a boolean indicating whether or not SO_KEEPALIVE is enabled.

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.

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 
  public static final short TIME_PORT = 135;
  public static void main(String[] argsthrows IOException{
    String hostName = null;
      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.print("RAW IP Address - (byte[]) : ");
      byte[] b1 = in.getAddress();
      for (int i=0; i< b1.length; i++) {
        if (i > 0) {

    catch (UnknownHostException  e)  {
    catch (IOException e) {

Output of  this program:

 C:\rose>java getKeepAlive

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

RAW IP Address - (byte[]) :


Download of this program.



[an error occurred while processing this directive]