Starting New Process

Discussion in 'Python' started by D, Jun 1, 2006.

  1. D

    D Guest

    Hello, I need to write a server program that performs the following
    tasks:

    1) Listens on TCP port 5555 for a connection
    2) When client connects, launches application (for example, vi), then
    closes connection with client
    3) Goes back to listening on TCP port 5555 for an incoming connection

    The main thing I need to make sure of is that when the server program
    closes, that the applications that were launched remain running (i.e. I
    would need to launch them independently of the server program). Any
    help as to how to do this would be greatly appreciated!
     
    D, Jun 1, 2006
    #1
    1. Advertising

  2. D

    D Guest

    Thanks, Jean-Paul - is there any way to do it without using Twisted,
    since I am not very familiar with it? (i.e. just using the os library)
    Thanks.

    Jean-Paul Calderone wrote:
    > On 1 Jun 2006 07:34:23 -0700, D <> wrote:
    > >Hello, I need to write a server program that performs the following
    > >tasks:
    > >
    > >1) Listens on TCP port 5555 for a connection
    > >2) When client connects, launches application (for example, vi), then
    > >closes connection with client
    > >3) Goes back to listening on TCP port 5555 for an incoming connection

    >
    > Untested:
    >
    > from twisted.internet import protocol, reactor
    >
    > class ViRunner(protocol.Protocol):
    > def connectionMade(self):
    > reactor.spawnProcess(
    > None,
    > '/usr/bin/setsid',
    > ['setsid', '/usr/bin/vi'])
    > self.transport.loseConnection()
    >
    > f = protocol.ServerFactory()
    > f.protocol = ViRunner
    > reactor.listenTCP(5555, f)
    > reactor.run()
    >
    > Jean-Paul
     
    D, Jun 1, 2006
    #2
    1. Advertising

  3. D

    Carl Guest

    D wrote:

    > Thanks, Jean-Paul - is there any way to do it without using Twisted,
    > since I am not very familiar with it? (i.e. just using the os library)
    > Thanks.
    >
    > Jean-Paul Calderone wrote:
    >> On 1 Jun 2006 07:34:23 -0700, D <> wrote:
    >> >Hello, I need to write a server program that performs the following
    >> >tasks:
    >> >
    >> >1) Listens on TCP port 5555 for a connection
    >> >2) When client connects, launches application (for example, vi), then
    >> >closes connection with client
    >> >3) Goes back to listening on TCP port 5555 for an incoming connection

    >>
    >> Untested:
    >>
    >> from twisted.internet import protocol, reactor
    >>
    >> class ViRunner(protocol.Protocol):
    >> def connectionMade(self):
    >> reactor.spawnProcess(
    >> None,
    >> '/usr/bin/setsid',
    >> ['setsid', '/usr/bin/vi'])
    >> self.transport.loseConnection()
    >>
    >> f = protocol.ServerFactory()
    >> f.protocol = ViRunner
    >> reactor.listenTCP(5555, f)
    >> reactor.run()
    >>
    >> Jean-Paul


    Use import socket ifyou don't want to use twisted (which is incredibly
    good). Google for "+socket +python +server" and you will find what you are
    looking for.

    See, for example,
    http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/wireless/5.html

    Carl
     
    Carl, Jun 1, 2006
    #3
  4. D

    D Guest

    Sorry, I should've specified - I'm familiar with sockets, but I was
    referring to spawning a 'vi' process independent of my Python app..


    Carl wrote:
    > D wrote:
    >
    > > Thanks, Jean-Paul - is there any way to do it without using Twisted,
    > > since I am not very familiar with it? (i.e. just using the os library)
    > > Thanks.
    > >
    > > Jean-Paul Calderone wrote:
    > >> On 1 Jun 2006 07:34:23 -0700, D <> wrote:
    > >> >Hello, I need to write a server program that performs the following
    > >> >tasks:
    > >> >
    > >> >1) Listens on TCP port 5555 for a connection
    > >> >2) When client connects, launches application (for example, vi), then
    > >> >closes connection with client
    > >> >3) Goes back to listening on TCP port 5555 for an incoming connection
    > >>
    > >> Untested:
    > >>
    > >> from twisted.internet import protocol, reactor
    > >>
    > >> class ViRunner(protocol.Protocol):
    > >> def connectionMade(self):
    > >> reactor.spawnProcess(
    > >> None,
    > >> '/usr/bin/setsid',
    > >> ['setsid', '/usr/bin/vi'])
    > >> self.transport.loseConnection()
    > >>
    > >> f = protocol.ServerFactory()
    > >> f.protocol = ViRunner
    > >> reactor.listenTCP(5555, f)
    > >> reactor.run()
    > >>
    > >> Jean-Paul

    >
    > Use import socket ifyou don't want to use twisted (which is incredibly
    > good). Google for "+socket +python +server" and you will find what you are
    > looking for.
    >
    > See, for example,
    > http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/wireless/5.html
    >
    > Carl
     
    D, Jun 1, 2006
    #4
  5. D

    D Guest

    Sorry to bring it back up, but is there a way to spawn the process
    without Twisted?
     
    D, Jun 5, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXN0b3BoZXI=?=

    Starting a new Process under a Specified Windows Account

    =?Utf-8?B?Q2hyaXN0b3BoZXI=?=, Jan 3, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,579
    Scott Allen
    Jan 3, 2005
  2. Replies:
    1
    Views:
    438
    Fredrik Lundh
    Jun 7, 2006
  3. gel
    Replies:
    7
    Views:
    3,360
    placid
    Jul 7, 2006
  4. lightning
    Replies:
    2
    Views:
    589
  5. Wally

    Starting new process from aspx page

    Wally, Feb 20, 2006, in forum: ASP .Net Web Services
    Replies:
    6
    Views:
    176
    Tiago Halm
    Dec 6, 2007
Loading...

Share This Page