Problems with an comet pilot

1 view
Skip to first unread message

Fernando

unread,
Sep 5, 2008, 7:03:36 AM9/5/08
to rocket-gwt
Hi,

I need to implement server pushing on my webapp and I'm doing some
testing with rocket-gwt.

I have delevoped an pilot using the sample code from the wiki and the
CometTest on the library.

My servlet:

public class SampleCometServletServlet extends CometServerServlet {
int counter;
protected void poll(CometConnection cometConnection) {
try {
Thread.sleep(5000);
} catch (InterruptedException ignore) {
}
CometPayload payload = new CometPayload(this.counter++);
System.out.println("Number: "+payload.getCounter());
cometConnection.push(payload);
}
}

My TestComet:

protected CometClient createComet(int nro) {
final TestGwtSerializationCometClient cometClient =
(TestGwtSerializationCometClient)
GWT.create(TestGwtSerializationCometClient.class);
cometClient.setNro(nro);
cometClient.setCallback(new CometCallback() {
public void onPayload(final Object object) {
final CometPayload payload = (CometPayload) object;
log.setText(log.getText() + "\n" + cometClient.getNro() +". Recieved:
" + payload.getCounter());
}
public void onTerminate() {
log.setText(log.getText() + "\n" + cometClient.getNro() +". Client
has had comet session terminated upon server request.");
}

public void onFailure(final Throwable cause) {
log.setText(log.getText() + "\n" + cometClient.getNro() +". Client
comet session failure, cause: " + cause.getMessage());
cause.printStackTrace();
}
});
return cometClient;
}

My web.xml:
<servlet>
<servlet-class>ejemplo.server.SampleCometServletServlet</servlet-
class>
<servlet-name>SimpleCometServlet</servlet-name>
<init-param>
<param-name>maximum-bytes-written</param-name>
<param-value>65536</param-value>
</init-param>
<init-param>
<param-name>connection-timeout</param-name>
<param-value>20000</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SimpleCometServlet</servlet-name>
<url-pattern>/comet</url-pattern>
</servlet-mapping>

The log after run it:
1. Client is starting new session...
1. Recieved: 0
1. Recieved: 0
1. Recieved: 1
1. Recieved: 0
1. Recieved: 1
1. Recieved: 2
1. Recieved: 0
1. Recieved: 1
1. Recieved: 2
1. Recieved: 3
1. Client is restarting new connection to server...
1. Client is stopping existing session...
1. Client is starting new session...
1. Recieved: 4
1. Recieved: 4
1. Recieved: 5
1. Recieved: 4
1. Recieved: 5
1. Recieved: 6
1. Recieved: 4
1. Recieved: 5
1. Recieved: 6
1. Recieved: 7
1. Client is restarting new connection to server...
1. Client is stopping existing session...
1. Client is starting new session...
1. Recieved: 8
1. Recieved: 8
1. Recieved: 9
1. Client is restarting new connection to server...
1. Client is stopping existing session...
1. Client is starting new session

I have two problems:

A. Each time the servlet push a new payload over the same connection,
the clientComet gets the previous sent payload with the new payload
and I get the following result:

1. Recieved: 0
1. Recieved: 0
1. Recieved: 1
1. Recieved: 0
1. Recieved: 1
1. Recieved: 2
1. Recieved: 0
1. Recieved: 1
1. Recieved: 2
1. Recieved: 3

... when the correct result should be like this:

1. Recieved: 0
1. Recieved: 1
1. Recieved: 2
1. Recieved: 3

Is this the expected behavior?

B. When I try to connect more than one client to the servlet, each
client recieve the same payload. In my case, I need to send different
payload to each client depending of the user logged on the application
(running on different browsers). Is it possible?

Thanks,

Fernando

mP

unread,
Sep 8, 2008, 9:22:27 AM9/8/08
to rocket-gwt
No. Check the demo for a sample...If that doesnt help post here again.

> B. When I try to connect more than one client to the servlet, each
> client recieve the same payload. In my case, I need to send different
> payload to each client depending of the user logged on the application
> (running on different browsers). Is it possible?
>

Yes, you will need to match connections with users and send the right
payload accordingly.

> Thanks,
>
> Fernando

Fernando

unread,
Sep 8, 2008, 1:18:06 PM9/8/08
to rocket-gwt
Hi Miroslav,

> No. Check the demo for a sample...If that doesnt help post here again.

I run rocket.remoting.test.comet.client.CometTest and it has the same
behaviour. I'm using rocket 0.55 and GWT 1.5.0.

The log:

Client is starting new session...
Server being polled
Server thread is sleeping for 3542
Server is flushing buffers.
Server being polled
Server thread is sleeping for 3273
Server is flushing buffers.
Server has written too many bytes written to client, will drop
connection, 1208/1024
Server is flushing buffers.
Server is closing its connection.
Client about to deserialize "[2,0,1,1,
[&quot;rocket.remoting.test.comet.client.TestCometPayload/
1749207429&quot;,&quot;11c42f28197&quot;],0,3]".
Client received
"rocket.remoting.test.comet.client.TestCometPayload@34b246, timestamp:
1220893901207"...
0. Client latency 3581 milliseconds, now: 125683, payload timestamp:
122102
Client about to deserialize "[2,0,1,1,
[&quot;rocket.remoting.test.comet.client.TestCometPayload/
1749207429&quot;,&quot;11c42f28197&quot;],0,3]".
Client received
"rocket.remoting.test.comet.client.TestCometPayload@f9d7ed, timestamp:
1220893901207"...
0. Client latency 3613 milliseconds, now: 125715, payload timestamp:
122102
Client about to deserialize "[2,1,1,1,
[&quot;rocket.remoting.test.comet.client.TestCometPayload/
1749207429&quot;,&quot;11c42f28e7a&quot;],0,3]".
Client received
"rocket.remoting.test.comet.client.TestCometPayload@109bcda,
timestamp: 1220893904506"...
1. Client latency 353 milliseconds, now: 125754, payload timestamp:
125401
Client is restarting new connection to server...
Client is stopping existing session...
Client is starting new session...

> Yes, you will need to match connections with users and send the right payload accordingly.

How can I do that? Using the CometClient.start() method? Some
parameter in the CometConnection?

Thanks
> > Fernando- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -

Inna

unread,
Sep 9, 2008, 11:42:15 AM9/9/08
to rocket-gwt
Hi Miroslav,
I've also noticed the same behavior as described by Fernando. I added
a unique ID to every payload that is sent from server to client and I
saw that previously sent payloads were sent over and over again.

Do you know what could be causing it? Looking at rocket source I don't
see anything wrong. Could it be that Tomcat causing this ( i am using
tomcat)?

I guess i could get around this problem by time stamping each payload
and checking on the client side that received payload is not older
than the previous one.
But still would be good to understand why it's happening on the first
place.

Thanks,
Inna
> > - Mostrar texto de la cita -- Hide quoted text -
>
> - Show quoted text -

Miroslav Pokorny

unread,
Sep 9, 2008, 4:35:36 PM9/9/08
to rocke...@googlegroups.com
I am not sure, have you tested in other browsers ?

> ["rocket.remoting.test.comet.client.TestCometPayload/
> 1749207429","11c42f28197"],0,3]".

> Client received
> "rocket.remoting.test.comet.client.TestCometPayload@34b246, timestamp:
> 1220893901207"...
> 0. Client latency 3581 milliseconds, now: 125683, payload timestamp:
> 122102
> Client about to deserialize "[2,0,1,1,
> ["rocket.remoting.test.comet.client.TestCometPayload/
> 1749207429","11c42f28197"],0,3]".

> Client received
> "rocket.remoting.test.comet.client.TestCometPayload@f9d7ed, timestamp:
> 1220893901207"...
> 0. Client latency 3613 milliseconds, now: 125715, payload timestamp:
> 122102
> Client about to deserialize "[2,1,1,1,
> ["rocket.remoting.test.comet.client.TestCometPayload/
> 1749207429","11c42f28e7a"],0,3]".
> - Show quoted text - de la cita -- Hide quoted text -

>
> - Show quoted text -




--
mP

mP

unread,
Sep 10, 2008, 4:14:28 AM9/10/08
to rocket-gwt
I have confirmed what is being reported. It appears to be a problem
with the servlet - which appears to be sending the same payload more
than once.

On Sep 10, 6:35 am, "Miroslav Pokorny" <miroslav.poko...@gmail.com>
wrote:

mP

unread,
Sep 10, 2008, 5:21:47 AM9/10/08
to rocket-gwt
I have fixed the comet servlet and updated the comet demo to assert
that payloads are nt delivered twice or missing...
I hope to have a new download up soon.

On Sep 10, 6:35 am, "Miroslav Pokorny" <miroslav.poko...@gmail.com>
wrote:

Fernando

unread,
Sep 10, 2008, 8:08:24 AM9/10/08
to rocket-gwt
Thanks!

Now, I have only one issue left to resolve:

>> B. When I try to connect more than one client to the servlet, each
>> client recieve the same payload. In my case, I need to send different
>> payload to each client depending of the user logged on the application
>> (running on different browsers). Is it possible?


>Yes, you will need to match connections with users and send the right
>payload accordingly.

How can I do that? Using the CometClient.start() method? Some
parameter in the CometConnection?

> > mP- Ocultar texto de la cita -

Miroslav Pokorny

unread,
Sep 10, 2008, 9:19:47 PM9/10/08
to rocke...@googlegroups.com, rocket-gwt

Sent from my iPhone

On 10/09/2008, at 10:08 PM, Fernando <ffis...@gmail.com> wrote:

>
> Thanks!
>
> Now, I have only one issue left to resolve:
>
>>> B. When I try to connect more than one client to the servlet, each
>>> client recieve the same payload. In my case, I need to send
>>> different
>>> payload to each client depending of the user logged on the
>>> application
>>> (running on different browsers). Is it possible?
>
>
>> Yes, you will need to match connections with users and send the right
>> payload accordingly.
>
> How can I do that? Using the CometClient.start() method? Some
> parameter in the CometConnection?
>

This is a problem that can only be solved on the server , with
cometconnection being the class that needs your logic to do the
routing of payloads to the appropriate user using perhaps something
like getting the user name from their session etc

Reply all
Reply to author
Forward
0 new messages