Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » CorbaRSS Feeds

Corba program to Write a Echo server and client with UDP server and client

Posted By: Milind Mishra     Category: Java     Views: 4670

Corba program to Write a Echo server and client with UDP server and client.

Code for Corba program to Write a Echo server and client with UDP server and client in Java

// Server

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

publicclass EServer
{
 publicstaticvoid 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.*;

publicclass EClient
{
 publicstaticvoid 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.


*************************************************************************/
  
Share: 



Milind Mishra
Milind Mishra author of Corba program to Write a Echo server and client with UDP server and client is from India.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!