Network Programming in Python
diffuser78 at gmail.com
diffuser78 at gmail.com
Thu Jun 22 16:02:22 EDT 2006
I have Python 2.4.2 on windows and Linux both. I got an import error.
how can we obtain the twisted libraries ?
When I try to run your code
Jean-Paul Calderone wrote:
> On 22 Jun 2006 12:02:14 -0700, diffuser78 at gmail.com wrote:
> >I am a newbie in python. I want to learn and implement a small
> >networking concept. Please help me. Every help is appreciated.
> >
> >I have one Linux Box and one Windows PC. I want to have a daemon
> >running on Windows PC which listens on some specicif port number. I
> >want to send a TCP/IP or UDP/IP packet from Linux box to Windows PC to
> >start some application. As Windows PC recieves such a packet from Linux
> >Box it executes a certain .exe file. I want to implement this concept.
> >
> >In short I want to remotely send command from Linux to Windows PC to
> >start a particular application.
> >
> >Thanks, Every help is appreciated.
> >
>
> Untested:
>
> from twisted.internet import protocol, reactor
> from twisted.protocols import basic
>
> COMMANDS = {
> "xterm": ("/usr/bin/xterm", {"DISPLAY": ":1.0"}),
> }
>
> class CommandLauncher(basic.LineReceiver):
> def lineReceived(self, line):
> try:
> cmd, env = COMMANDS[line]
> except KeyError:
> self.sendLine("error")
> else:
> reactor.spawnProcess(None, cmd, env=env)
> self.sendLine("okay")
>
> f = protocol.ServerFactory()
> f.protocol = CommandLauncher
> reactor.listenTCP(12345, f)
> reactor.run()
>
> You should be able to telnet to this (port 12345) and type in
> names of commands for it to run. Of course, xterm isn't a very
> good win32 program to run but I couldn't think of a better example.
> You could also write a program to send command requests to this
> server, instead of using telnet.
>
> Jean-Paul
More information about the Python-list
mailing list