[Twisted-Python] Twisted Endpoints and WebSocket / Autobahn

Glyph glyph at twistedmatrix.com
Fri Dec 13 06:32:22 MST 2013


On Dec 12, 2013, at 12:29 AM, Tobias Oberstein <tobias.oberstein at tavendo.de> wrote:

> Hi,
> 
> I am working on Twisted Endpoint support in Autobahn https://github.com/tavendo/AutobahnPython.

Yay!

> So far, I made Autobahn able to talk WebSocket _over_ arbitrary Twisted Endpoints, e.g. WebSocket over Unix domain sockets works. This is already quite nifty.
> 
> Is there anything like Twisted Endpoints for Processes and/or Serial? Like:
> 
> endpoint = serverFromString(reactor,"process:program=/usr/local/bin/myprogram")
> 
> or
> 
> endpoint = serverFromString(reactor,"serial:port=/dev/tty1:baudrate=115000")

Yes and no.

For serial port support, see <https://twistedmatrix.com/trac/ticket/4847>.  For subprocess support, <https://twistedmatrix.com/documents/current/api/twisted.internet.endpoints.ProcessEndpoint.html>.

However, process support is unfinished, as you can see in <https://twistedmatrix.com/trac/ticket/5813>; there still needs to be a string parser plugin, so you can't do what you suggest with serverFromString.

I hope you'll poke those tickets along through the process.

> That would allow to talk WebSocket over stdin/stdout to a program or a serial conneced device. Both can be useful in certain situations.

And that would be awesome.

> I'd also like to add the other: creating an Twisted Endpoint _from_ an Autobahn server/client to be able to talk any (stream) protocol _over_ WebSocket (like SSH or VNC over WebSocket).
> 
> endpoint = serverFromString(reactor,"websocket:tcp:80:url=ws://myhostname.com/somepath")

There's totally a plugin architecture for this, and I'm excited for you to use it :-).

One quick comment though: would you be OK with using 'autobahn' as your identifier rather than 'websocket'?  There are still plans to include basic websocket support within Twisted itself and it would be a shame to start conflicting on that identifier.

> I guess I need to provide an implementation of
> http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.ITransport.html
> 
> What else? Is there some docs or recipe?

Sadly it seems that although <http://twistedmatrix.com/documents/current/core/howto/endpoints.html> alludes to the plugin API, it doesn't actually link to it.

The way that you add a new type of endpoint to the string parser is by registering a Twisted plugin (assuming that you know how to do that) providing   <https://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IStreamServerEndpointStringParser.html>.

Hopefully the API documentation there is helpful; from there you'll need to write implementations of IStreamServerEndpoint, IListeningPort, and ITransport; the breadcrumbs should be laid out well enough that it's pretty clear where each of those needs to be though.

Hope that helps, and thanks for actually wanting to use these plugin APIs we worked so hard on,

-glyph


More information about the Twisted-Python mailing list