I'm writing a server-client application. It's a 2 week work schedule. The snapshot below is the client GUI with a fictitious dataset.
Pressing the apply button submits the calendar contents to the server via the following code:
public boolean saveToFile() {
try {
// serialTableData is class variable of type: ArrayList<MHSCalendarEntry>
// tableData is a class variable of type: ObserverableList<MHSCalendarEntry>
serialTableData = new ArrayList<>(tableData);
System.out.println("Sending calendar:\n" + MHSCalendarEntry.toString(serialTableData));
heartbeatProxy.writeObject(serialTableData);
return true;
}
catch (IOException ex) {
alert();
return false;
}
}
Debugging
I've got a print statement on the client side before sending data (as seen in the above code) and print statement on the server after receiving data.
The problem:
When I click apply for the first time everything works correctly:
Any amendments thereafter don't transfer:
Client print statement
Server print statement
What I've tried:
I rewrote the client side to isolate the problem, this code bypasses the serialTableData and tableData variables and also simulates multiple dataset entries by using Thread.sleep() :
package Admin.GUI;
import com.cworner.mhscalendar.calendarentry.MHSCalendarEntry;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
/**
*
* @author Chris
*/
public class AdminTest {
private ArrayList<MHSCalendarEntry> mhs;
ObjectInputStream input;
ObjectOutputStream output;
Socket socket;
public AdminTest() {
try {
socket = new Socket("localhost", 8000);
output = new ObjectOutputStream(socket.getOutputStream());
input = new ObjectInputStream(socket.getInputStream());
System.out.println("Blank calendar recieved");
mhs = (ArrayList<MHSCalendarEntry>)input.readObject();
System.out.println("Calendar:\n" + MHSCalendarEntry.toString(mhs));
System.out.println("Sending 1st calendar");
mhs = new ArrayList<> (Arrays.asList(
new MHSCalendarEntry("", "1", "", "", "" ,"", "#" ,"", "", "", "", ""),
new MHSCalendarEntry("", "", "2", "", "" ,"" , "#","", "", "", "", ""),
new MHSCalendarEntry("", "", "", "3", "" ,"" , "#","", "", "", "", ""),
new MHSCalendarEntry("", "", "", "", "" ,"" , "#","", "", "", "", ""),
new MHSCalendarEntry("", "", "", "", "" ,"", "#" ,"", "", "", "", ""),
new MHSCalendarEntry("", "", "", "", "" ,"", "#" ,"", "", "", "", "")));
System.out.println("Calendar:\n" + MHSCalendarEntry.toString(mhs));
output.writeObject(mhs);
Thread.sleep(1000 * 10);
System.out.println("Sending 2nd calendar");
mhs = new ArrayList<> (Arrays.asList(
new MHSCalendarEntry("", "1", "", "", "" ,"", "#" ,"", "", "", "", ""),
new MHSCalendarEntry("", "", "2", "", "" ,"" , "#","", "", "", "", ""),
new MHSCalendarEntry("", "", "", "3", "" ,"" , "#","", "", "", "", ""),
new MHSCalendarEntry("", "", "", "", "4" ,"" , "#","", "", "", "", ""),
new MHSCalendarEntry("", "", "", "", "" ,"5", "#" ,"", "", "", "", ""),
new MHSCalendarEntry("", "", "", "", "" ,"", "#" ,"", "", "", "", "")));
System.out.println("Calendar:\n" + MHSCalendarEntry.toString(mhs));
output.writeObject(mhs);
}
catch(IOException | ClassNotFoundException | InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
AdminTest test = new AdminTest();
}
}
This worked. Which suggests the problem lies with the variables like they're not being updated. But the print statement contradicts this by showing the variables are up to date before sending them to the server.






After 2 weeks of debugging and researching, this explained the problem.
Answered in a separate thread