Java Reference
In-Depth Information
else if
(message.indexOf("<EVENT>") >
#
0) {
// the client is pulling the events
for
(
int
i
#
0; i < eventList.size(); i
!!
)
output.println("<"
!
(String)eventList.get(i)
!
">" );
output.println("<NOEVENT>");
output.flush();
}
else if
(message.indexOf("MSG:")
>
#
0 && parser !
#
null
) {
// receives a message with a command from the
// remote client
String msg
#
message.substring(5).trim();
// decodes the message and executes the command
parser.decode(msg);
}
}
}
catch
(SocketException se) {
// quits this activity
process.stopActivity(
this
.getURL());
}
catch
(Exception e) { e.printStackTrace(); }
}
public void
quit() {
// closes the sockets
try
{
input.close();
output.close();
socket.close();
}
catch
(IOException ioe) { ioe.printStackTrace(); }
// quits the service
process.stopActivity(service.getURL());
}
public void
update(DEvent event) {
if
(parser
##
null
)
return
;
// delegates the parser to encode the event
StringBuffer sb
#
parser.encode(event);
if
(pushMode) {
// sends the event to the client
output.println(sb.toString());
output.flush();
}
else
eventList.add(sb.toString());
output.flush();
}
}