Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Client Socket Information 
 

In this section, you will learn how to get client socket information. This is a very simple program of java network. Here, we have used the class named ClientSocketInformation.java that implement the constructor of the Socket class passing two arguments a

 

Client Socket Information

                         

In this section, you will learn how to get client socket information. This is a very simple program of java network. Here, we have used the class named ClientSocketInformation.java that implement the constructor of the Socket class passing two arguments as hostName and TIME_PORT. This program throws an IOException for the exception handling. This exception is thrown to indicate an I/O problem of some sort occurred.

Here, we are going to explore a method to retrieve the host name of the local system in a very simple way. In this way we find out the Local address, Local host information, reuseAddress, and address of the local system in a very simple manner.

Code Description

Here we are going to define about all the using method.

isBound(): This is a boolean type method. This method returns the binding state of the socket.
isConnected():  This method inform about the socket connectivity that is connected from server or may not.
getSoTimeout(): This method  returns the setting for So_TIMEOUT 0 returns implies that the option is disabled.
getSoLinger(): This is the method returns setting for SO_LINGER. -1 returns imply that the option is disabled.

Here is code of this program:
import java.net.*;
import java.io.*;
import java.net.InetAddress;

public class ClientSocketInformation{
  public static final short TIME_PORT = 135;
  public static void main(String[] argsthrows IOException{
    String hostName= null;
    try{
      Socket socket= new Socket(hostName,TIME_PORT);
      System.out.println();
      System.out.println("Socket is =" + socket);
      System.out.println("is socket bound? ="+ socket.isBound());
      System.out.println("is socket Connected? ="+ socket.isConnected());
      System.out.println("show time out = "+ socket.getSoTimeout());
      System.out.println("so linger =" + socket.getSoLinger());
      System.out.println("TCP no Delay =" + socket.getTcpNoDelay());
      System.out.println("Traffic class =" + socket.getTrafficClass());
      System.out.println("channel is =" + socket.getChannel());
      System.out.println("Reuse address is =" + socket.getReuseAddress());
      System.out.println("close =" + socket.isClosed());
      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]);
      }
      System.out.println();
      System.out.println("Is Loopback Address?      : " + in.isLoopbackAddress());
      System.out.println("Is Multicast Address?     : " + in.isMulticastAddress());
      System.out.println("\n");
      InetAddress address = socket.getLocalAddress();
      System.out.println("Local address =" + address);
     }
    catch (UnknownHostException  e)  {
      e.printStackTrace();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}


Here Output of this  program:

C:\amar>javac ClientSocketInformation.java
C:\amar>java ClientSocketInformation

Socket is =Socket[addr=localhost/127.0.0.1,port=135,localport=1329]
is socket bound? =true
is socket Connected? =true
show time out = 0
so linger =-1
TCP no Delay =false
Traffic class =0
channel is =null
Reuse address is =false
close =false
localhost/127.0.0.1

RAW IP Address - (byte[]) : 127.0.0.1
Is Loopback Address? : true
Is Multicast Address? : false

Local address =/127.0.0.1

C:\amar>

 

Download of this program.

 

                         

» View all related tutorials
Related Tags: c com forms server orm form network socket io sed request return opera ai for work wait to base pos

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.