diff --git a/src/networking/ServerNetworking.java b/src/networking/ServerNetworking.java index a0427b5..a75ac67 100644 --- a/src/networking/ServerNetworking.java +++ b/src/networking/ServerNetworking.java @@ -11,10 +11,12 @@ public class ServerNetworking { + String thermostatIP; + // Listens on receiveCurrentTempPORT and outputs the received int to console - public int receiveCurrentTemp(int receiveCurrentTempPORT) throws Exception { + public void receiveCurrentTemp() throws Exception { // Open a receiver socket - ServerSocket listener = new ServerSocket(receiveCurrentTempPORT); + ServerSocket listener = new ServerSocket(7000); try { // This stays running continuously once called while (true) { @@ -27,7 +29,6 @@ public int receiveCurrentTemp(int receiveCurrentTempPORT) throws Exception { // Parses the input stream int currentTemperature = Integer.parseInt(input.readLine()); // Outputs the current temperature to the console - return currentTemperature; } finally { socket.close(); } @@ -39,11 +40,10 @@ public int receiveCurrentTemp(int receiveCurrentTempPORT) throws Exception { } // Sends the desired temperature on port sendDesiredTempPORT - public void sendDesiredTemp(int sendDesiredTempPORT, int desiredTemperature, - String thermostatIP) + public void sendDesiredTemp(int desiredTemperature, String thermostatIP) throws Exception { // Opens a sending port - Socket sender = new Socket(thermostatIP, sendDesiredTempPORT); + Socket sender = new Socket(thermostatIP, 7001); try { while (true) { // Instantiate a printwriter so we can write to the output stream @@ -58,9 +58,9 @@ public void sendDesiredTemp(int sendDesiredTempPORT, int desiredTemperature, } // Receive multicast messages from the thermostats - public void receiveMutlticast(int receiveMulticastPORT) throws Exception { + public void receiveMutlticast() throws Exception { // Opens the receiving port - MulticastSocket multicastReceiver = new MulticastSocket(receiveMulticastPORT); + MulticastSocket multicastReceiver = new MulticastSocket(7002); // Join the All Hosts network segment, as defined by RFC 5771 multicastReceiver.joinGroup(InetAddress.getByName("224.0.0.1")); // Instantiate the DatagramPacket and buffer size diff --git a/src/networking/ThermostatNetworking.java b/src/networking/ThermostatNetworking.java index a3eedd6..e2f3075 100644 --- a/src/networking/ThermostatNetworking.java +++ b/src/networking/ThermostatNetworking.java @@ -10,11 +10,13 @@ import java.net.Socket; public class ThermostatNetworking { + + String serverIP; // Listens on receiveDesiredTempPORT and outputs the received int to console - public void receiveDesiredTemp(int receiveDesiredTempPORT) throws Exception { + public void receiveDesiredTemp() throws Exception { // Open a receiver socket - ServerSocket listener = new ServerSocket(receiveDesiredTempPORT); + ServerSocket listener = new ServerSocket(7001); try { while (true) { // Sets the socket to an accept state @@ -38,10 +40,10 @@ public void receiveDesiredTemp(int receiveDesiredTempPORT) throws Exception { } // Sends the current temperature on port sendCurrentTempPORT - public void sendInfo(int sendCurrentTempPORT, int currentTemperature) + public void sendInfo(int currentTemperature) throws Exception { // Open a sending port - Socket sender = new Socket(serverIP, sendCurrentTempPORT); + Socket sender = new Socket(serverIP, 7000); try { while (true) { // Instantiate a printwriter so we can write to the output stream @@ -56,19 +58,19 @@ public void sendInfo(int sendCurrentTempPORT, int currentTemperature) } // Send multicast messages to the server to update the database's IP entry - public void updateIP(int sendMulticastPORT) throws Exception { + public void updateIP() throws Exception { // Instantiate the DatagramPacket and buffer size byte[] buf = new byte[256]; DatagramPacket packet = new DatagramPacket(buf, buf.length); // Join the All Hosts network segment, as defined by RFC 5771 - MulticastSocket socket = new MulticastSocket(sendMulticastPORT); + MulticastSocket socket = new MulticastSocket(7002); socket.joinGroup(InetAddress.getByName("224.0.0.1")); try { while (true) { socket.send(packet); } } finally { - updateIP + } } diff --git a/src/server/server.java b/src/server/server.java index d9d89bf..2843406 100644 --- a/src/server/server.java +++ b/src/server/server.java @@ -6,12 +6,6 @@ public class server extends ServerNetworking implements Thermostatable { - // Listen for the current temperature on port 7000 - int receiveCurrentTempPORT = 7000; - // Send the desired temperature on port 7001 - int sendDesiredTempPORT = 7001; - // Receive thermostat device multicast messages - int receiveMulticastPORT = 7002; // Desired temperature int desiredTemperature; // Thermostat IP address @@ -29,7 +23,7 @@ public server() { } public void receiveCurrentTemp() throws Exception { - super.receiveCurrentTemp(receiveCurrentTempPORT); + super.receiveCurrentTemp(); } public boolean createUser(String email, String password, String ip, String serialpermission) { diff --git a/src/thermostat/ThermostatDevice.java b/src/thermostat/ThermostatDevice.java index 958623e..6947543 100644 --- a/src/thermostat/ThermostatDevice.java +++ b/src/thermostat/ThermostatDevice.java @@ -18,15 +18,6 @@ public class ThermostatDevice extends ThermostatNetworking implements Deviceable List actuatorList; private Timer clock; private String serialNumber; - - // Send the current temperature on port 7000 - int sendCurrentTempPORT = 7000; - // Listen for the desired temperature on port 7001 - int receiveDesiredTempPORT = 7001; - // Send mutlicast packets to notify the server that the device exists - int sendMulticastPORT = 7002; - // Server IP address - String serverIP; public ThermostatDevice(Integer updateIntervalInSeconds){ try { @@ -47,8 +38,6 @@ public ThermostatDevice(Integer updateIntervalInSeconds){ this.clock = new Timer(updateIntervalInSeconds*1000, this); this.clock.start(); - // String serverIP = this.getServerIP(); - } public void sensorUpdateEvent(Sensorable sensor) {