[Twisted-Python] Information on new endpoints API?
Albert Brandl
albert.brandl at weiermayer.com
Tue Jun 14 03:37:29 EDT 2011
On Sun, Jun 12, 2011 at 01:22:35PM -0000, exarkun at twistedmatrix.com wrote:
> `twisted.internet.endpoints.serverFromString` is one way you might get
> this endpoint (in particular, I would emphasize that serverFromString is
> really only meant to construct an endpoint if you *have* to start with a
> string - as you do when you are reading a configuration file).
This works also quite well when you have different kinds of connection
in the testing and production environment. We read data from a GPS
device. For testing purposes, we want to feed the NMEA telegrams into
the server using a TCP connection, but the device is connected to the
server on a serial port.
We've defined a constant GPS_PORT as "SERIAL:/dev/ttyS2:baudrate=4800"
for the production environment and "tcp:1049" for the test environment
(SERIAL is not yet part of the endpoint framework - I've started working
on issue 4847, but didn't find time yet to polish the code and submit a
patch - sorry).
We're now able to create a service by calling
gps_service = strports.service(GPS_PORT, gps_factory)
Depending on the environment, the server listens either on TCP port 1049
or the serial device /dev/ttyS2.
A nice side effect is that I have a central place where the connection
details for all kinds of services are defined - should any port change,
I know where to fix it.
Regards,
--
Albert Brandl
Weiermayer Solutions GmbH | Abteistraße 12, A-4813 Altmünster
phone: +43 (0) 720 70 30 14 | fax: +43 (0) 7612 20 3 56
web: http://www.weiermayer.com
More information about the Twisted-Python
mailing list