Java Tutorial

 
 
 
 
// Server

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

public class EServer
{
 public static void main(String[] args) throws IOException 
 {

  ServerSocket S = new ServerSocket(3000);

  while(true)
  {
   Socket Client = S.accept();

   InputStream in = Client.getInputStream();

   DataInputStream Dis = new DataInputStream(in);

   System.out.println(Dis.readUTF());

   Client = new Socket(\"localhost\",4000);

  BufferedReader buff = new BufferedReader(new InputStreamReader (System.in));

   String Str = buff.readLine();

   OutputStream out = Client.getOutputStream();

   DataOutputStream Dos = new DataOutputStream(out);

   Str = \"Server Says :: \" + Str;

   Dos.writeUTF(Str);

   Client.close();

  }

 }

}


// Client 

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

public class EClient
{
 public static void main(String[] args) throws IOException 
 {
  Socket C = new Socket(\"localhost\",3000);
  BufferedReader buff = new BufferedReader(new InputStreamReader (System.in));
  String Str = buff.readLine();

  OutputStream out = C.getOutputStream();

  DataOutputStream Dos = new DataOutputStream(out);

  Dos.writeUTF(\"Client Say :: \" + Str);
  Dos.flush();

  ServerSocket S = new ServerSocket(4000);
  Socket Client = S.accept();
  InputStream in = Client.getInputStream();
  DataInputStream Dis = new DataInputStream(in);
  System.out.println(Dis.readUTF());
  Client.close();
 }
}



OUTPUT :

=========  Client  ============

C:\\jdk1.1.3\\bin>javac EClient.java

C:\\jdk1.1.3\\bin>java EClient
hi, how are you Server?
Server Says :: Fine, Thankyou. Bye.



=========  Server =============
C:\\jdk1.1.3\\bin>javac EServer.java

C:\\jdk1.1.3\\bin>java EServer
Client Say :: hi, how are you Server?
Fine, Thankyou. Bye.


*************************************************************************/

    Related Post:
  1. Program to declare and initialize Boolean variables and print them on the Standard Output Device

  2. Program to show an example of Concatination of Strings

  3. Program to show an example of Calling a Base Class Method from a Derived Class

  4. Program to display triangle of numbers

  5. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

  6. An applet program to add two numbers where data is entered in TextField

  7. RMI application for getting the final total price of the shopping list with some of the following items and quantities chosen by the user

  8. Program which calls the method sort(int []a) which throws the Exception ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException

  9. Program to copy the elements of an array into another array in reverse order and print them

  10. Program to show the use of Increment and Decrement Operators

  11. RMI program of count server and client

  12. Program using Switch case to compute the net amount to be paid by a customer

  13. An applet program to display text

  14. Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back

  15. Program which will read a string and rewrite it in the alphabetical order

  16. Program to show the use of Bitwise Operator (^) XOR (Exclusive OR)

  17. Program to display reverse $ tree

  18. Corba program of reverse string

  19. program which takes a long sentence from the client passes to the server,server separates out each word and sends them back to client in reverse order

  20. Program to show the use of Conditional OR Operator (||) in If Statements

 
 
Didn't find what you were looking for? Find more on Corba program to Write a Echo server and client with UDP server and client