jri at deepamehta.de
So Jan 12 22:52:21 CET 2014
On Jan 12, 2014, at 19:55, Jörn Weißenborn wrote:
> I see some problems in this implementation. As I see it, multiple plugins using websockets would both receive all events and respond. This would confuse possible clients, which would maybe want to talk with only one of those plugins.
The dm4-websockets plugin separates user-written plugins properly. One plugin does not see the messages bound to other plugins. Not on client-side and not on server-side. (The plugin would not know how to interpret these messages.)
- when you invoke the WebSocket constructor you MUST specify your plugin's URI as the 2nd argument. The URI is received by the server while the connection handshake. So each WebSocket connection is associated with the plugin that initiated that connection.
- the framework invokes the websocketTextMessage() hook only for the plugin associated with the connection through which the message has arrived.
- when you call the WebSocketsService's broadcast() method you must specify your plugin's URI as the 1st argument. The framework then broadcasts the message only through the connections associated with that plugin.
These conditions are illustrated by the dm4-websockets-example application.
> Also I might want, e.g. when a client requests something, to be able to send it to this particular client.
When the client *requests* something it might be more natural to do a regular HTTP request. You don't necessarily need WebSockets then.
Anyway, one case is actually not yet supported by the dm4-websockets plugin: *pushing* a message to a *particular* client (instead of broadcasting).
I will extend the dm4-websockets plugin soon, in order to support pushing to a particular client.
> Another thing is, that if one implements a plugin to use websockets, one is basically writing an API for DeepaMehta, at least in my humble opinion.
No. A plugin using WebSockets contains only application-specific logic (in contrast to framework-level logic). Also the message format and protocol are application-specific. The underlying generic message format and protocol is WebSockets.
Mehr Informationen über die Mailingliste devel