Java Tutorial

 
 
 
 
// Server

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

public class news_server
{
 public static void main(String[] args) throws IOException 
 {
  int ch1;
  String str;
    FileReader fr = new FileReader(\"news.txt\");
    BufferedReader br = new BufferedReader(fr);


  Socket C = new Socket(\"localhost\",4000);
  OutputStream out = C.getOutputStream();

  DataOutputStream Dos = new DataOutputStream(out);


  while( (str = br.readLine()) != null)
  {
         Dos.writeUTF(\"Latest News (From Server ) :: \" + str);
  }
  Dos.flush();
  fr.close();
 }
}


// Client

//                               Client 
//               =====    


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

public class news_client
{
 public static void main(String[] args) throws IOException 
 {
  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

News.txt
=========================
India won the Worldcup by beating
Australia by 6 wkt.
===========================


//  Server
C:\\jdk1.1.3\\bin>javac news_server.java

C:\\jdk1.1.3\\bin>java news_server


//  Client
C:\\jdk1.1.3\\bin>java news_client
Latest News (From Server ) :: India won the Worldcup by beating
Australia by 6 wkt.

    Related Post:
  1. RMI application for counting factorial of a given number.

  2. An applet program that concatenates two string entered in TextField

  3. Program to show the use of Conditional AND Operator (&&) in If Statements

  4. Program to Concat Strings

  5. Program to show an example of Polymorphism

  6. An applet program of showing new document using showDocument(URL) method

  7. An applet program to perform selection sort

  8. Program to read input from the Standard Input Device

  9. Program that accepts a shopping list of items from the command line and stores them in a vector. Also provide facility to perform operation

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

  11. 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

  12. Program to display attributes of a specified file

  13. Program to show the use of If-Else Statement

  14. Program to show an example of creating String objects from Character Arrays

  15. Program to show an example of creating Character Arrays from String objects

  16. Program that demonstrates type casting

  17. 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

  18. Add,delete,Update in LISTS

  19. Program to show an example of modifying String objects

  20. Program sets up a String variable containing a paragraph of text of your choice. Extract the words from the text and sort them into alphabetical order