Skip to content

Commit

Permalink
Changed method definitions and return types to fit restructuring of t…
Browse files Browse the repository at this point in the history
…he networking flow.
  • Loading branch information
pid1 committed Apr 24, 2015
1 parent be5bf78 commit c5b5bff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
16 changes: 8 additions & 8 deletions src/networking/ServerNetworking.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/networking/ThermostatNetworking.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

}
}

Expand Down
8 changes: 1 addition & 7 deletions src/server/server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
11 changes: 0 additions & 11 deletions src/thermostat/ThermostatDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ public class ThermostatDevice extends ThermostatNetworking implements Deviceable
List<Actuatorable> 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 {
Expand All @@ -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) {
Expand Down

0 comments on commit c5b5bff

Please sign in to comment.