[deepamehta-devel] WebSockets

Jörg Richter jri at deepamehta.de
Di Jan 7 04:40:04 CET 2014


I like to announce my first WebSockets experiences with DM.
As a technology demo I created a new plugin (for usage info see the README):

What this plugin does:
- Setup a WebSocket server at ws://localhost:8081/ and wait for WebSocket clients
- Listen for Topic Update events from the DM Core and push them to all connected WebSocket clients (broadcast)
- Write all WebSocket messages (handshake, open, message, frame, control, close) to the DM server log
- Provide a WebSocket client at http://localhost:8080/de.deepamehta.websockets/

What the WebSocket client does:
- Establish a WebSocket connection to ws://localhost:8081/
- Send a greeting message to the server once the connection is established
- Log all received messages (Topic Update events) to the browser console
- Log the connection open and close events to the browser console

So, the dm4-websockets plugin demonstrates all technical aspects of WebSockets. It performs no useful task, and it is not yet extensible by 3rd party plugin developers. It's just a tech demo.

How the dm4-websockets plugin is realized:
- Bundle a Jetty 7 web server and the jetty-websocket extension
- Instantiate a Jetty Server on port 8081 and set a WebSocketHandler

That means when the dm4-websockets plugin is installed the Jetty binaries are bundled *twice* and 2 Jetty servers are instantiated (each on its own port).

What I've learned so far:
- DM *can* provide WebSockets without relying on OPS4J Pax Web (an OSGi HTTP Service implementation).
- DM can *not* use the Jetty web server that is bundled with Apache Felix HTTP Jetty (the OSGi HTTP Service implementation used by DM) because ...
	- The OSGi 4.2 HTTP Service specification does not allow for accessing the WebSockets capabilities of the underlying web server. So we must setup a WebSocket server on our own. And for doing that we can *not* use the bundled Jetty because ...
	- The org.eclipse.jetty.* Java packages of the Apache Felix HTTP Jetty bundle are not exported.

That means the dm4-websockets plugin must bundle and instantiate its own WebSocket server anyway. (This must not necessarily be a full-blown web server like Jetty.)

Please correct my if I'm wrong. I wish there would be a way to not bundle the Jetty binaries twice, and to not instantiate 2 Jetty servers, and to not open 2 HTTP ports.

Next possible step from my side:
- Make the dm4-websockets plugin extensible by 3rd party plugin developers. That is abstracting the WebSocket server (and the Jetty API) away and provide the plugin developer a framework for handling client-side and server-side WebSocket messages.

Don't hesitate to sketch out your cool DM server push application here.
This would be a good help for me when designing the framework.


Mehr Informationen über die Mailingliste devel