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. Program to display attributes of a specified file

  2. Program that will count the number of lines in each file that is specified on the command line

  3. Program of telnet server - client

  4. Application for counting factorial of a given number

  5. Program to declare and initialize Boolean variables and print them on the Standard Output Device

  6. Program to search an element in an array using Linear Search

  7. Program to reverse the number eg given no : - 12345, output want :- 54321

  8. An applet program to draw different shapes

  9. Program to display triangle of numbers

  10. Program to show the use of Logical or Boolean Negation i.e. NOT (!)

  11. An applet program to display barchart of given data

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

  13. Encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time after each word in the sent

  14. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

  15. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  16. Program to read the ballots and count the votes cast for each candidate using an array variable count

  17. Program to show the use of some Character Methods

  18. An applet program that display blinking rectangle

  19. Program to print triangle of numbers

  20. Program to print some text on the same line using multiple print statements