Closed KBKrause closed 6 years ago
private StudentPanelInterface getStudentPanelAtIndex(int index)
{
StudentPanelInterface retval = null;
retval = (StudentPanel)studentTabs.getComponentAt(index);
return retval;
}
private int getIndexOfPanelWithIdentifier(String ident)
{
System.out.println("Ident searching for is " + ident);
int retval = 0;
for (int i = 0; i < studentTabs.getTabCount(); i++)
{
System.out.println("IP of tab at " + i + " : " + ((StudentPanel)studentTabs.getComponentAt(i)).getIP());
// TODO
// Eventually, tabs should have names of students.
// Then the if statement below should become
if (((StudentPanel)studentTabs.getComponentAt(i)).getIP().equals(ident))
//if (studentTabs.getTitleAt(i).equals(ident));
{
System.out.println("Found a match");
retval = i;
}
}
System.out.println("Index is " + retval);
return retval;
}
Index of student panels changes each time a new student is added. So instead of using an extra method to get the index of the corresponding panel, use a new function that will get a panel based on an identifier and return the reference to that panel, rather than its index. Pseudocode:
private StudentPanelInterface getStudentPanelWithIdentifier(String identifier) {
StudentPanelInterface retval = null;
for (StudentPanelInterface spi : studentTabs) {
if (spi.getIP().equals(identifier) {
retval = spi; }
}
return retval;
}
if (tokens[0].equals("h"))
{
if (ipListing.contains(clientIP) == false)
{
System.out.println(clientIP + " has connected for the first time");
ipListing.add(clientIP);
updateGUI("h:" + clientIP + ":" + tokens[2]);
}
else
{
System.out.println("Client " + clientIP + " has attempted to initialize more than once");
}
}
// "Update case"
else if (tokens[0].equals("u"))
{
String updateRequest = Inet.decodeUpdate(tokens[1]);
updateGUI("u:" + clientIP + ":" + updateRequest);
//System.out.println(clientIP + " says: " + updateRequest);
}
IPs reported by "h" and "u" tokens were different, should work now on different machines.
This might be because the proxy is receiving messages from the same IP and considers it the same machine, when it should be creating a new panel for each student.
However, the update messages do not contain information about the sender, so this should be tested on two actual different machines.