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 display following things on the client machine a)date and time of the server machine b)date and time of the client machine and difference

  2. An application that combines several classes and interface

  3. Program to show the use of Labeled Break Statement

  4. Program of telnet server - client

  5. Program to show the use of operator (<<) Shift Left filling with zero from the right

  6. Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

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

  8. Program to display bank account

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

  10. Program to sort the contents of an array using Bubble Sort

  11. Even number ,Prime no. ,Factorial of a number

  12. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

  13. Program of storing and retrieving integers using data streams on a single file

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

  15. Program to convert the given temperature in faherenhiet to celsius using the following conversion formula C= F- 32/1.8

  16. Program to show insertion of StringBuffer, String objects and other Basic Data Types into a StringBuffer object

  17. Corba program of UDP client server application which sends the news to the client. Server takes the news from the NewsDataFile located at the server

  18. Program to show an example of using Abstract Class and Abstract Method

  19. Program of date server and client

  20. An applet program to draw Polygon Graph with given data

 
 
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