Thursday, 8 August 2013

Create Input Stream - Client - In Java Programming



On the client side, you can create an output stream to send information to the server socket using the class PrintStream or DataOutputStream of java.io: 

On the client side, you can use the DataInputStream class to create an input stream to receive response from the server:
  


DataInputStream input;
   try {
        input = new    DataInputStream(MyClient.getInputStream());
   }
   catch (IOException e) {
       System.out.println(e);
   } 

PrintStream output;
   try {
        output = new PrintStream(MyClient.getOutputStream()); }
   catch (IOException e) {
         System.out.println(e);
   }

The class PrintStream has methods for displaying textual representation of Java primitive data types.

you may use the DataOutputStream   DataOutputStream output;

   try {
         output = new DataOutputStream(MyClient.getOutputStream());
   }
   catch (IOException e) {
        System.out.println(e);
   }

The class DataOutputStream allows you to write Java primitive data types; many of its methods write a single Java primitive type to the output stream.
The method writeBytes is a useful one. 

How to  open a Socket on Server in Java Socket Programming

0 comments:

Post a Comment

Products :