Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package sensorClient;
  7. import java.io.*;
  8. import java.net.*;
  9. import java.text.SimpleDateFormat;
  10. import java.util.*;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import java.util.Date.*;
  14. public class Client {
  15.  
  16.  
  17. private static Socket sock;
  18. //private static Socket ;
  19. private static ServerSocket sockSuperVisor;
  20. private static String Zone;
  21. private static int Battery=100;
  22. private static BufferedReader bufferReader;
  23. private static BufferedReader bufferReader1;
  24. private static PrintStream os;
  25. private static Socket clientSocket = null;
  26.  
  27.  
  28. public static void main(String[] args) throws IOException {
  29. try {
  30. sock = new Socket("localhost", 4444);
  31. sockSuperVisor = new ServerSocket( 4445);
  32. clientSocket = sockSuperVisor.accept();
  33. System.out.println("Accepted connection : " + clientSocket);
  34. bufferReader = new BufferedReader(new InputStreamReader(System.in));
  35. bufferReader1 = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  36. // Scanner in = new Scanner(sockSuperVisor.getInputStream());
  37. } catch (Exception e) {
  38. System.err.println("Error - Try again.");
  39. System.exit(1);
  40. }
  41.  
  42. os = new PrintStream(sock.getOutputStream());
  43.  
  44. boolean done = false;
  45. //os.println("validate");
  46.  
  47. while (!done) {
  48. try {
  49.  
  50. switch (selectAction()) {
  51. case "latitude":
  52. os.println("latitude");
  53. latitude();
  54. break;
  55. case "longitude":
  56. os.println("longitude");
  57. longitude();
  58. break;
  59. case "temp":
  60. os.println("temp");
  61. temp();
  62. break;
  63. case "condition":
  64. os.println("condition");
  65. condition();
  66. break;
  67. case "windspeed":
  68. os.println("windspeed");
  69. windspeed();
  70. break;
  71. case "pressure":
  72. os.println("pressure");
  73. pressure();
  74. break;
  75. case "humidity":
  76. os.println("humidity");
  77. humidity();
  78. break;
  79.  
  80.  
  81.  
  82.  
  83.  
  84. }
  85. } catch (Exception e) {
  86. System.err.println("Wrong command");
  87. }
  88. }
  89.  
  90. sock.close();
  91. }
  92.  
  93. public static String selectAction() throws IOException {
  94. System.out.println("");
  95.  
  96. System.out.println("exit - Exit.");
  97. System.out.print("\nSelect one Option: ");
  98.  
  99. // return bufferReader.readLine();
  100. return bufferReader1.readLine();
  101. }
  102.  
  103. public static void latitude() throws IOException {
  104. PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
  105. Scanner in = new Scanner(sock.getInputStream());
  106. out.println(Zone);
  107. System.err.println(in.nextLine());
  108.  
  109. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  110. }
  111.  
  112. public static void longitude() throws IOException {
  113. PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
  114. Scanner in = new Scanner(sock.getInputStream());
  115. out.println(Zone);
  116. System.err.println(in.nextLine());
  117.  
  118. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  119. }
  120.  
  121. public static void temp() throws IOException {
  122. PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
  123. Scanner in = new Scanner(sock.getInputStream());
  124. out.println(Zone);
  125. System.err.println(in.nextLine());
  126.  
  127. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  128. }
  129.  
  130. public static void condition() throws IOException {
  131. PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
  132. Scanner in = new Scanner(sock.getInputStream());
  133. out.println(Zone);
  134. System.err.println(in.nextLine());
  135.  
  136. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  137. }
  138.  
  139. public static void windspeed() throws IOException {
  140. PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
  141. Scanner in = new Scanner(sock.getInputStream());
  142. out.println(Zone);
  143. System.err.println(in.nextLine());
  144.  
  145. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  146. }
  147.  
  148. public static void pressure() throws IOException {
  149. PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
  150. Scanner in = new Scanner(sock.getInputStream());
  151. out.println(Zone);
  152. System.err.println(in.nextLine());
  153.  
  154. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  155. }
  156.  
  157. public static void humidity() throws IOException {
  158. PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
  159. Scanner in = new Scanner(sock.getInputStream());
  160. out.println(Zone);
  161. System.err.println(in.nextLine());
  162.  
  163. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  164. }
  165.  
  166.  
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement