Advertisement
Guest User

first

a guest
Feb 8th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. // this is client program that will ask for the temperture
  2. //this will also display the temperture in celsius after the server converts it
  3.  
  4. import java.io.*;
  5. import java.net.*;
  6. import java.util.*;
  7.  
  8.  
  9. public class first
  10. {
  11.  
  12. public static void main(String[] args)
  13.   {
  14.  
  15.     DataOutputStream toServer;
  16.     DataInputStream fromServer;
  17.         try
  18.     {
  19.       // Create a socket to connect to the server
  20.       Socket socket = new Socket("localhost", 8000);
  21.  
  22.       // Create input stream to receive data
  23.       // from the server
  24.       fromServer = new DataInputStream(socket.getInputStream());
  25.  
  26.       // Create a output stream to send data to the server
  27.       toServer = new DataOutputStream(socket.getOutputStream());
  28.  
  29.         Scanner scan= new Scanner (System.in);
  30.  
  31.       // Continuously send radius and receive area
  32.       // from the server
  33.       while (true)
  34.       {
  35.         // Read the temperture from the keyboard
  36.         System.out.print("Please enter a temperture in Fahrenheit ");
  37.         double Temp=scan.nextDouble();
  38.        
  39.         // Send the temperture to the server
  40.         toServer.writeDouble(Temp);
  41.           toServer.flush();
  42.  
  43.        
  44.         // Convert string to double
  45.         double celsius = fromServer.readDouble();
  46.  
  47.         // Print Temperature in celsius on the console
  48.         System.out.println("Temperature in celsius received from the server is "
  49.           +celsius);
  50.       }
  51.    
  52.  
  53.  
  54.   }
  55.   catch (IOException ex)
  56.     {
  57.       System.err.println(ex);
  58.     }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement