Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
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 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.

 

                         

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 
Latest Searches:
sample notepad source
linkedlist <E>
login database
jdk1.4features
MPEG4/MP3 Streaming En
what are front end and
java games.
Javadoc
json lib/componen...]=
Photoshop Photo Retouc
LinuxCaixaMÑ?â??â??â?¬
free source jsp n serv
upload file through se
Linux Caixa Mะ�ะ
�г???????�г?????
java mail api
header footer menu bod
delete data in mysql d
JScrollPane
Uploading Employee Pro
IPO Charts
Eclipse3.4EJB
saving files under fol
Numbers
HOW TO counting billio
Java in Flex
j2me stringItem hyperl
c:forEach
SAVING CSV FILE IN JAV
Struts File Download E
types of exceptions
jframe table give code
applet viewer tag
button boom
data input stream
download struts-config
definition of web.xml
struts tutorial downlo
create zip file
Scanner
welcome page
Aspect_oriented progra
mapping dispatch actio
file uploading code us
typecast between strin
java Game manager
downloadawebpageusings
Swing Jlabel images
json lib/components/co
JSP radiobuttons
Thread Sleep Method
generatepdffileforexce
convert string array t
Fireworks Special Effe
java / menu bar
display message in app
example of Jtext area
j2me stringItem static
jsp mysql combo box
Hash maps in struts2
bean:define
Display error in JSP
java program to find s
json lib/errors.php?er
AUMLtutorial
Create resource bundle
class diagrams in UML
identifyobjectsonawebp
Take user input using
J-Integra Excel exampl
sea
howtoretrievedatabasei
login eample code usin
Java Checkbox Example
jdbc question
how to create tree usi
java servelt programe
'string variable in sw
free download taglibs-
j2me stringItem
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.