Starting New Process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D

    #1

    Starting New Process

    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

    #2
    Re: Starting New Process

    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:[color=blue]
    > On 1 Jun 2006 07:34:23 -0700, D <duncanm255@hot mail.com> wrote:[color=green]
    > >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[/color]
    >
    > Untested:
    >
    > from twisted.interne t import protocol, reactor
    >
    > class ViRunner(protoc ol.Protocol):
    > def connectionMade( self):
    > reactor.spawnPr ocess(
    > None,
    > '/usr/bin/setsid',
    > ['setsid', '/usr/bin/vi'])
    > self.transport. loseConnection( )
    >
    > f = protocol.Server Factory()
    > f.protocol = ViRunner
    > reactor.listenT CP(5555, f)
    > reactor.run()
    >
    > Jean-Paul[/color]

    Comment

    • Carl

      #3
      Re: Starting New Process

      D wrote:
      [color=blue]
      > 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:[color=green]
      >> On 1 Jun 2006 07:34:23 -0700, D <duncanm255@hot mail.com> wrote:[color=darkred]
      >> >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[/color]
      >>
      >> Untested:
      >>
      >> from twisted.interne t import protocol, reactor
      >>
      >> class ViRunner(protoc ol.Protocol):
      >> def connectionMade( self):
      >> reactor.spawnPr ocess(
      >> None,
      >> '/usr/bin/setsid',
      >> ['setsid', '/usr/bin/vi'])
      >> self.transport. loseConnection( )
      >>
      >> f = protocol.Server Factory()
      >> f.protocol = ViRunner
      >> reactor.listenT CP(5555, f)
      >> reactor.run()
      >>
      >> Jean-Paul[/color][/color]

      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,


      Carl

      Comment

      • D

        #4
        Re: Starting New Process

        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:[color=blue]
        > D wrote:
        >[color=green]
        > > 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:[color=darkred]
        > >> On 1 Jun 2006 07:34:23 -0700, D <duncanm255@hot mail.com> 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.interne t import protocol, reactor
        > >>
        > >> class ViRunner(protoc ol.Protocol):
        > >> def connectionMade( self):
        > >> reactor.spawnPr ocess(
        > >> None,
        > >> '/usr/bin/setsid',
        > >> ['setsid', '/usr/bin/vi'])
        > >> self.transport. loseConnection( )
        > >>
        > >> f = protocol.Server Factory()
        > >> f.protocol = ViRunner
        > >> reactor.listenT CP(5555, f)
        > >> reactor.run()
        > >>
        > >> Jean-Paul[/color][/color]
        >
        > 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/Glam...ireless/5.html
        >
        > Carl[/color]

        Comment

        • D

          #5
          Re: Starting New Process

          Sorry to bring it back up, but is there a way to spawn the process
          without Twisted?

          Comment

          Working...