Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package sensorClient;
- import java.io.*;
- import java.net.*;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import java.util.Date.*;
- public class Client {
- private static Socket sock;
- //private static Socket ;
- private static ServerSocket sockSuperVisor;
- private static String Zone;
- private static int Battery=100;
- private static BufferedReader bufferReader;
- private static BufferedReader bufferReader1;
- private static PrintStream os;
- private static Socket clientSocket = null;
- public static void main(String[] args) throws IOException {
- try {
- sock = new Socket("localhost", 4444);
- sockSuperVisor = new ServerSocket( 4445);
- clientSocket = sockSuperVisor.accept();
- System.out.println("Accepted connection : " + clientSocket);
- bufferReader = new BufferedReader(new InputStreamReader(System.in));
- bufferReader1 = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
- // Scanner in = new Scanner(sockSuperVisor.getInputStream());
- } catch (Exception e) {
- System.err.println("Error - Try again.");
- System.exit(1);
- }
- os = new PrintStream(sock.getOutputStream());
- boolean done = false;
- //os.println("validate");
- while (!done) {
- try {
- switch (selectAction()) {
- case "latitude":
- os.println("latitude");
- latitude();
- break;
- case "longitude":
- os.println("longitude");
- longitude();
- break;
- case "temp":
- os.println("temp");
- temp();
- break;
- case "condition":
- os.println("condition");
- condition();
- break;
- case "windspeed":
- os.println("windspeed");
- windspeed();
- break;
- case "pressure":
- os.println("pressure");
- pressure();
- break;
- case "humidity":
- os.println("humidity");
- humidity();
- break;
- }
- } catch (Exception e) {
- System.err.println("Wrong command");
- }
- }
- sock.close();
- }
- public static String selectAction() throws IOException {
- System.out.println("");
- System.out.println("exit - Exit.");
- System.out.print("\nSelect one Option: ");
- // return bufferReader.readLine();
- return bufferReader1.readLine();
- }
- public static void latitude() throws IOException {
- PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
- Scanner in = new Scanner(sock.getInputStream());
- out.println(Zone);
- System.err.println(in.nextLine());
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public static void longitude() throws IOException {
- PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
- Scanner in = new Scanner(sock.getInputStream());
- out.println(Zone);
- System.err.println(in.nextLine());
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public static void temp() throws IOException {
- PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
- Scanner in = new Scanner(sock.getInputStream());
- out.println(Zone);
- System.err.println(in.nextLine());
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public static void condition() throws IOException {
- PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
- Scanner in = new Scanner(sock.getInputStream());
- out.println(Zone);
- System.err.println(in.nextLine());
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public static void windspeed() throws IOException {
- PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
- Scanner in = new Scanner(sock.getInputStream());
- out.println(Zone);
- System.err.println(in.nextLine());
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public static void pressure() throws IOException {
- PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
- Scanner in = new Scanner(sock.getInputStream());
- out.println(Zone);
- System.err.println(in.nextLine());
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- public static void humidity() throws IOException {
- PrintWriter out = new PrintWriter(sock.getOutputStream(),true);
- Scanner in = new Scanner(sock.getInputStream());
- out.println(Zone);
- System.err.println(in.nextLine());
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement