You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Maxim Solodovnik <so...@gmail.com> on 2012/12/20 13:37:52 UTC

WebSocketPushBroadcaster broadcastAll bug or feature

Hello All,

Does anybody ever used WebSocketPushBroadcaster broadcastAll method?

Either I use it incorrectly or it doesn't work.

The following code doesn't send any messages:

class ChatMessage extends TextMessage implements IWebSocketPushMessage,
Serializable {
private static final long serialVersionUID = -3802182673895471248L;

public ChatMessage(String msg) {
super(msg);
}
}

IWebSocketConnectionRegistry reg =
IWebSocketSettings.Holder.get(getApplication()).getConnectionRegistry();

new WebSocketPushBroadcaster(reg).broadcastAll(getApplication(), new
ChatMessage(message));


same time the following code works as expected:

IWebSocketConnectionRegistry reg =
IWebSocketSettings.Holder.get(getApplication()).getConnectionRegistry();
for (IWebSocketConnection c : reg.getConnections(getApplication())) {
try {
c.sendMessage(message);
} catch(Exception e) {
log.error("Error while sending message", e);
}
}


Am I doing something wrong?
There are no exceptions in the log or something.


another thing not very clear to me: broadcastAll
requires IWebSocketPushMessage as a parameter. But this interface is not
implemented by any wicket classes. Is it by design?

-- 
WBR
Maxim aka solomax

Re: WebSocketPushBroadcaster broadcastAll bug or feature

Posted by Martin Grigorov <mg...@apache.org>.
Hi Maxin,

Here is an example:
https://github.com/martin-g/blogs/tree/master/wicket6-websocket-broadcast

IWebSocketPushMessage is a special interface for messages which are sent by
a service at the server side, then broadcasted to all pages with active
WebSocket connections, i.e. the page and all its components and behaviors
receive the message in #onEvent() and each component/behavior can write to
the client side thru the WebSocketRequestHandler.

Your example with c.sendMessage(message); is almost the same, just that the
message is not passed to all components and behaviors but goes directly to
the client.


On Thu, Dec 20, 2012 at 2:37 PM, Maxim Solodovnik <so...@gmail.com>wrote:

> Hello All,
>
> Does anybody ever used WebSocketPushBroadcaster broadcastAll method?
>
> Either I use it incorrectly or it doesn't work.
>
> The following code doesn't send any messages:
>
> class ChatMessage extends TextMessage implements IWebSocketPushMessage,
> Serializable {
> private static final long serialVersionUID = -3802182673895471248L;
>
> public ChatMessage(String msg) {
> super(msg);
> }
> }
>
> IWebSocketConnectionRegistry reg =
> IWebSocketSettings.Holder.get(getApplication()).getConnectionRegistry();
>
> new WebSocketPushBroadcaster(reg).broadcastAll(getApplication(), new
> ChatMessage(message));
>
>
> same time the following code works as expected:
>
> IWebSocketConnectionRegistry reg =
> IWebSocketSettings.Holder.get(getApplication()).getConnectionRegistry();
> for (IWebSocketConnection c : reg.getConnections(getApplication())) {
> try {
> c.sendMessage(message);
> } catch(Exception e) {
> log.error("Error while sending message", e);
> }
> }
>
>
> Am I doing something wrong?
> There are no exceptions in the log or something.
>
>
> another thing not very clear to me: broadcastAll
> requires IWebSocketPushMessage as a parameter. But this interface is not
> implemented by any wicket classes. Is it by design?
>
> --
> WBR
> Maxim aka solomax
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>