Salut,
Sreenivas Munnangi wrote:
> Jeanfrancois Arcand wrote:
>> Salut,
>>
>> Sreenivas Munnangi wrote:
>>> Hi,
>>>
>>> We are able to get comet work with a simple java client and we are
>>> planning on enhancing it for production use.
>>>
>>> Basically we are planning to use a single servlet (attached war with
>>> servlet) which will serve multiple clients using contextPath and
>>> corresponding handler. Somehow the client (attached client code) doesn't
>>> get the response back and it keeps hanging. Based on the debug info,
>>> the onEvent method got invoked (made sure to flush the writer several
>>> times) but the response is not received by the client. Do you spot
>>> anything obvious ?
>>
>> Not sure I understand why you invoking flush so many times :-) Just
>> one it should works.
> I know, just to make sure :-)
>>
>> First, I haven't try but:
>>
>>> protected void doPost(HttpServletRequest req, HttpServletResponse
>>> res)
>>> throws ServletException, IOException {
>>> String contextPath = req.getParameter("script");
>>> String message = req.getParameter("message");
>>> CometEngine engine = CometEngine.getEngine();
>>> if (message == null) {
>>> if (contextPath != null) {
>>> CometContext cc = engine.getCometContext(contextPath);
>>> if (cc == null) {
>>> cc = engine.register(contextPath);
>>> cc.setExpirationDelay(30000 * 1000);
>>> CometMsgHandler handler = new CometMsgHandler();
>>> handler.attach(res);
>>> cc.addCometHandler(handler);
>>> cc.notify("init");
>>> } }
>>> } else {
>>> CometContext cc = engine.getCometContext(contextPath);
>>> if (cc != null) {
>>> cc.notify(message);
>>> }
>>>
>>> }
>>> }
>>
>> if cc == null you will never notify, hence no msg. You should add some
>> debug statement here to make sure cc is never null.
> We are making that sure by using println statements which I removed for
> code clarity.
>>
>> Can you install ngrep.sourceforge.net or wireshark and make sure you
>> are writting something back? One way to make sure is to resume the
>> CometHandler inside the onEvent method, e.g invoking:
>
>>
>> event.getCometContext().resumeCometHandler(this).
> I'll try that.
>>
>> Also from:
>>
>>> if (message == null) {
>>> if (contextPath != null) {
>>> CometContext cc = engine.getCometContext(contextPath);
>>> if (cc == null) {
>>> cc = engine.register(contextPath);
>>> cc.setExpirationDelay(30000 * 1000);
>>> CometMsgHandler handler = new CometMsgHandler();
>>> handler.attach(res);
>>> cc.addCometHandler(handler);
>>> cc.notify("init");
>>> } }
>>
>> if the cc != null you are doing nothing, which explain probably why
>> you aren't geting any data.
>
> No, pl. see the else block where I am making sure message is also not
> null before using notify
>
> } else {
> CometContext cc = engine.getCometContext(contextPath);
> if (cc != null) {
> cc.notify(message);
> }
Right, but if it is null, nothing will happens :-) Can yu add some debug
statement there to make sure it is never null?
A+
-- jeanfrancois
>
> }
>
>>
>> A+
>>
>> --Jeanfrancois
>>
>>
>>
>>>
>>> Pl. let us know if you need more info.
>>>
>>> Appreciate your help.
>>>
>>> thanks
>>> sreeni
>>>
>>>
>>>
>