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 show the use of Conditional (Ternary) Operator

  2. Program to show the use of some Math Methods

  3. Program to declare, initialize and print an array of integers

  4. Do the following for the Array Insert the element in the array,delete an element from the array,search for a particular element Create multiple thread

  5. An applet program of linear sort

  6. Program to extract a portion of a character string and print the extracted string

  7. Program to show an example of Multiple Levels of Inheritance

  8. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  9. Develop a CORBA application that takes a string from client and returns whether it is palindrome

  10. Given a list of marks ranging form 0 to 100, write a program to compute and print the number of students marks

  11. Dialog Boxes

  12. Program to show an example of extracting subStrings from a String

  13. An applet program to display barchart of given data

  14. Pass the marks of 10 students from the client side design a servlet, which takes these marks and returns the number of students who obtained first cls

  15. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  16. Program to show an example of using a Static Nested Class

  17. File handling program to copy bytes from one file to another

  18. An applet program to draw concentric circle in center of the canvas

  19. Program that maintains employee database of an education system

  20. Program to show an example of using initialization block to initialize the data members of a class

 
 
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