I have a program with selected code posted. Every second time through the client-server send-receive cycle, the client does not receive what the server sends.
In brief, client calls sendShowAll(), sending an int to the server which the server receives ok. The client also calls handleServerMessages, to listen for the server's reply.
The server, in a forever loop, receives the SHOWALL int and calls the single method sendShowAll(), followed by flush().
sendShowAll collects records using a JDBC Connection and assembles them into an array list. So far, all is well, the server verifies that it has done all these things. Since the array list is small, the server will send one partial packet. This is determined in sendShowAll, which then calls sendPartialPacket.
The server gets to here every time also, but something happens now that doesn't make sense. The server calls writeInt(PARTIALPACKET), and the client doesn't see it. This would tell the client to receive the partial packet and alter the data model for the table. The client only sees this message every second time this entire process iterates. Instead, the client sees BYE, a writeInt() call signaling that there is nothing more to send now, and the clilent needn't block on i/o.
I am baffled; please help if you can.
The client calls these two methods to update a table:
[code}
ch.sendShowAll();
model.handleServerMessages();[/code]
The server does this:{code]
while (true)
{
int command = in.readInt();
System.out.println("in main,command received: " +command);
switch(command)
{
case SHOWALL:
{
ServerRecord.sendShowAll(out,connection);
out.flush();
System.out.println("in AddressServer; showall sent");
} break;
case DELETE:
{
int recNum = in.readInt();
ServerRecord.deleteRecord(connection,recNum);
System.out.println("deleted rec " + recNum);
} break;
case UPDATE:
{
ServerRecord sR = new ServerRecord();
sR.readRecordFromSocket(in);
System.out.println("Updated "+ sR);
sR.updateDB(connection);
}
case NEW:
{
ServerRecord sR = new ServerRecord();
sR.readRecordFromSocket(in);
System.out.println(sR);
sR.writeNewRecordToDB(connection);
} break;
}//end switch
out.writeInt(BYE);
System.out.println("bye code sent");
[/code]
Then does this:
and this: