// is using a ObjectOutputStream to write to us
din = new ObjectInputStream(socket.getInputStream());
// Over and over, forever ...
while (true) {
// ... read the next message ...
CommandIF comm = null;
try {
comm = (CommandIF) din.readObject();
} catch (ClassNotFoundException e) {
log
.error("Class cast breaking up. Try some packaging stuff");
e.printStackTrace();
} catch (IOException ioe) {
// seems like socket is reset
// lets update list
// server.removeConnection(senderName, socket);
}
// ... tell the world ...
server.updatePeerList(comm, socket);
/*
* extraction
*/
String message = comm.getMessage();
System.out.println("Sending " + message);
String pureMessage = message;
InetAddress inet = socket.getInetAddress();
String sock = inet.getHostAddress();
senderName = comm.getMsgFrom();
ServerThread.verifyList(senderName);
tracer.tracerDb(sock, comm.getMsgFrom(), pureMessage, comm
.getRecipientNames());
// ... and have the server send it to all clients
if (comm.getCommand().equals(ProtocolConstants.COMMAND_SEND)) {
if (comm.getRecipientNames().get(0).equals(
ProtocolConstants.SEND_TO_ALL)) {
server.sendToAll(comm);
} else {
// surely user is trying to send message but not to all
// peers
if (!comm.isSendingFile()) {
server.sendToAll(comm);
} else {
// user is trying to send file
CommandIF fileCommand = handleFileRequest(comm);
server.sendToAll(fileCommand);
}
}
} else if (comm.getCommand().equals(
ProtocolConstants.DELETE_FILE)) {