Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this is client program that will ask for the temperture
- //this will also display the temperture in celsius after the server converts it
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class first
- {
- public static void main(String[] args)
- {
- DataOutputStream toServer;
- DataInputStream fromServer;
- try
- {
- // Create a socket to connect to the server
- Socket socket = new Socket("localhost", 8000);
- // Create input stream to receive data
- // from the server
- fromServer = new DataInputStream(socket.getInputStream());
- // Create a output stream to send data to the server
- toServer = new DataOutputStream(socket.getOutputStream());
- Scanner scan= new Scanner (System.in);
- // Continuously send radius and receive area
- // from the server
- while (true)
- {
- // Read the temperture from the keyboard
- System.out.print("Please enter a temperture in Fahrenheit ");
- double Temp=scan.nextDouble();
- // Send the temperture to the server
- toServer.writeDouble(Temp);
- toServer.flush();
- // Convert string to double
- double celsius = fromServer.readDouble();
- // Print Temperature in celsius on the console
- System.out.println("Temperature in celsius received from the server is "
- +celsius);
- }
- }
- catch (IOException ex)
- {
- System.err.println(ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement