Client/Server Question

Dennis Benzinger Dennis.Benzinger at gmx.net
Fri Jul 28 16:42:53 EDT 2006


diffuser78 at gmail.com wrote:
> My server.py looks like this
> 
> ---------------------------------------------CODE----------------------------------
> #!/usr/bin/env python
> import socket
> import sys
> import os
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> host = ''
> port = 2000
> 
> s.bind((host,port))
> s.listen(1)
> conn, addr = s.accept()
> print 'client is at', addr
> 
> while True:
> 	data = conn.recv(1000000)
> 	if (data == 'MaxSim'):
> 		print 'MaxiSim'
> 		os.system('notepad')
> 	elif (data == 'Driving Sim'):
> 		print 'Driving Sim'
> 		os.system('explorer')
> 	elif (data == 'SHUTDOWN'):
> 		print 'Shutting down...'
> 		os.system('shutdown -s')
> 		conn.close()
> 		break
> -------------------------------------------CODE
> END-------------------------------------
> 
> I am running this above program on a windows machine. My client is a
> Linux box. What I want to achieve is that server.py should follows
> instructions till I send a 'SHUTDOWN' command upon which it should shut
> down.
> 
> When I run this program and suppose send 'MaxSim' to it, it launches
> notepad.exe fine, but then after that it doesn't accept subsequent
> command. I want is that it should accept subsequent commands like
> Driving Sim and launch windows explorer etc untill I send a 'SHUTDOWN'
> command.
> 
> Any help on this, it will be greatly appreciated.
> 


os.system() blocks until the called program has finished. Use the 
subprocess module <http://docs.python.org/lib/module-subprocess.html>:

<untested_code>

import subprocess

subprocess.Popen("notepad")

</untested_code>


Dennis



More information about the Python-list mailing list