Advertisement
Guest User

myTCPclient

a guest
Mar 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class myTCPclient
  5. {
  6. public static void main (String args[])
  7. {
  8. try
  9. {
  10. InputStream input = System.in;
  11. InputStreamReader rd = new InputStreamReader (input);
  12. BufferedReader brd = new BufferedReader (rd);
  13.  
  14. System.out.print("Please enter the radius: ");
  15. String rad = brd.readLine();
  16.  
  17. int d = Integer.parseInt(rad);
  18.  
  19. //*********************************//
  20. int sport = 4444;
  21. InetAddress serverADD = InetAddress.getByName("127.0.0.1");
  22.  
  23. Socket send = new Socket(serverADD, sport);
  24.  
  25. DataInputStream instream = new DataInputStream(send.getInputStream()); //terima data
  26. DataOutputStream outstream = new DataOutputStream(send.getOutputStream()); // hantar data
  27.  
  28. outstream.writeInt(d);
  29.  
  30. double area = instream.readDouble();
  31.  
  32. send.close();
  33.  
  34.  
  35. System.out.println("Given radius = " + d);
  36. System.out.println("Area = " + area);
  37.  
  38. }
  39. catch(IOException ioerr)
  40. {
  41. System.out.println(ioerr);
  42. }
  43.  
  44.  
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement