Merge lp:~vds/ubuntuone-windows-installer/twisted_ipc_1 into lp:ubuntuone-windows-installer/beta

Proposed by Vincenzo Di Somma
Status: Merged
Merged at revision: 60
Proposed branch: lp:~vds/ubuntuone-windows-installer/twisted_ipc_1
Merge into: lp:ubuntuone-windows-installer/beta
Diff against target: 51 lines (+42/-0)
1 file modified
src/ipcservice/ipcservice.py (+42/-0)
To merge this branch: bzr merge lp:~vds/ubuntuone-windows-installer/twisted_ipc_1
Reviewer Review Type Date Requested Status
Nicola Larosa (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+32351@code.launchpad.net

Description of the change

Very basic ipc services.

To post a comment you must log in.
35. By vincenzo di somma <vds@blackrain>

removed useless test file

Revision history for this message
Manuel de la Peña (mandel) wrote :

Great starting step. +1

review: Approve
Revision history for this message
Nicola Larosa (teknico) wrote :

This is fairly low level, and old style.

A more extensible structure would be to use applications and services: http://twistedmatrix.com/documents/current/core/howto/application.html , but then you could not pass command line arguments to the twistd command running the .tac file.

Another possibiliy would be to write a plugin: http://twistedmatrix.com/documents/current/core/howto/plugin.html , but it's a bit verbose, and I'm not sure about command line options.

The API servers use .tac files taking the parameters from the config files and the environments, do you absolutely have to use command line options?

review: Needs Information
Revision history for this message
Nicola Larosa (teknico) wrote :

You could possibly do something like this: http://twistedmatrix.com/pipermail/twisted-python/2005-May/010542.html , if you really need command line options.

Revision history for this message
Vincenzo Di Somma (vds) wrote :

Thanks for the useful comments, I'm going through the docs!
Just to give more context, this small daemon is supposed to on the windows desktop not on a server, the port will be assigned by the C# application when the it starts. The C# application could write the .tac itself but as we don't see any other configuration or parameter we want to use and we don't expect to reuse this daemon in other ways a .toc file seems an overkill, we just need two port numbers.

Revision history for this message
Nicola Larosa (teknico) wrote :

Ok, if it's not a long-running daemon, and its lifetime is controlled by another application, then probably using twistd and .tac file is uncalled for.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'src/ipcservice'
2=== added file 'src/ipcservice/__init__.py'
3=== added file 'src/ipcservice/ipcservice.py'
4--- src/ipcservice/ipcservice.py 1970-01-01 00:00:00 +0000
5+++ src/ipcservice/ipcservice.py 2010-08-11 16:44:49 +0000
6@@ -0,0 +1,42 @@
7+import sys
8+from twisted.internet.protocol import Factory, Protocol, ClientFactory
9+from twisted.internet import reactor
10+
11+
12+class IPCServerProtocol(Protocol):
13+ """ """
14+ def dataReceived(self, data):
15+ print "doing something with: ", data
16+
17+class IPCServerFactory(Factory):
18+ """ """
19+ protocol = IPCServerProtocol
20+
21+
22+class IPCClientProtocol(Protocol):
23+ """ """
24+
25+ def send(self, data):
26+ """ """
27+ self.transport.write("sending: %s" % data)
28+
29+
30+class IPCClientFactory(ClientFactory):
31+ """ """
32+ protocol = IPCClientProtocol
33+
34+
35+def main(server_port, client_port):
36+ reactor.listenTCP(server_port, IPCServerFactory())
37+ reactor.connectTCP("localhost", client_port, IPCClientFactory())
38+ reactor.run()
39+
40+if __name__ == '__main__':
41+ args = sys.argv
42+ if len(args) < 3:
43+ server_port = 8007
44+ client_port = 8008
45+ else:
46+ server_port = args[1]
47+ client_port = args[2]
48+ main(server_port, client_port)
49
50=== added directory 'src/ipcservice/tests'
51=== added file 'src/ipcservice/tests/__init__.py'

Subscribers

People subscribed via source and target branches