473,769 Members | 5,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Client/Server Question

My server.py looks like this

---------------------------------------------CODE----------------------------------
#!/usr/bin/env python
import socket
import sys
import os

s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
host = ''
port = 2000

s.bind((host,po rt))
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr

while True:
data = conn.recv(10000 00)
if (data == 'MaxSim'):
print 'MaxiSim'
os.system('note pad')
elif (data == 'Driving Sim'):
print 'Driving Sim'
os.system('expl orer')
elif (data == 'SHUTDOWN'):
print 'Shutting down...'
os.system('shut down -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.

Jul 28 '06 #1
9 1335
di********@gmai l.com wrote:
My server.py looks like this

---------------------------------------------CODE----------------------------------
#!/usr/bin/env python
import socket
import sys
import os

s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
host = ''
port = 2000

s.bind((host,po rt))
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr

while True:
data = conn.recv(10000 00)
if (data == 'MaxSim'):
print 'MaxiSim'
os.system('note pad')
elif (data == 'Driving Sim'):
print 'Driving Sim'
os.system('expl orer')
elif (data == 'SHUTDOWN'):
print 'Shutting down...'
os.system('shut down -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_cod e>

import subprocess

subprocess.Pope n("notepad")

</untested_code>
Dennis
Jul 28 '06 #2
Is os.system() going to be deprecated in future ?.....I read somewhere.

Dennis Benzinger wrote:
di********@gmai l.com wrote:
My server.py looks like this

---------------------------------------------CODE----------------------------------
#!/usr/bin/env python
import socket
import sys
import os

s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
host = ''
port = 2000

s.bind((host,po rt))
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr

while True:
data = conn.recv(10000 00)
if (data == 'MaxSim'):
print 'MaxiSim'
os.system('note pad')
elif (data == 'Driving Sim'):
print 'Driving Sim'
os.system('expl orer')
elif (data == 'SHUTDOWN'):
print 'Shutting down...'
os.system('shut down -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_cod e>

import subprocess

subprocess.Pope n("notepad")

</untested_code>
Dennis
Jul 28 '06 #3
i highly doubt it.
http://www.google.com/search?domains...&submit=search
di********@gmai l.com wrote:
Is os.system() going to be deprecated in future ?.....I read somewhere.

Dennis Benzinger wrote:
di********@gmai l.com wrote:
My server.py looks like this
>
---------------------------------------------CODE----------------------------------
#!/usr/bin/env python
import socket
import sys
import os
>
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
host = ''
port = 2000
>
s.bind((host,po rt))
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr
>
while True:
data = conn.recv(10000 00)
if (data == 'MaxSim'):
print 'MaxiSim'
os.system('note pad')
elif (data == 'Driving Sim'):
print 'Driving Sim'
os.system('expl orer')
elif (data == 'SHUTDOWN'):
print 'Shutting down...'
os.system('shut down -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_cod e>

import subprocess

subprocess.Pope n("notepad")

</untested_code>
Dennis
Jul 28 '06 #4
you might want to look at sshd. if you're on a windows box, you may
need cygwin. if you're on linux, you either already have it, or it's in
your package manager.

di********@gmai l.com wrote:
My server.py looks like this

---------------------------------------------CODE----------------------------------
#!/usr/bin/env python
import socket
import sys
import os

s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
host = ''
port = 2000

s.bind((host,po rt))
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr

while True:
data = conn.recv(10000 00)
if (data == 'MaxSim'):
print 'MaxiSim'
os.system('note pad')
elif (data == 'Driving Sim'):
print 'Driving Sim'
os.system('expl orer')
elif (data == 'SHUTDOWN'):
print 'Shutting down...'
os.system('shut down -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.
Jul 28 '06 #5
di********@gmai l.com wrote:
Is os.system() going to be deprecated in future ?.....I read somewhere.
[...]
Sometime in the future it will. But that won't happen soon. Read the
second paragraph of "Backwards Compatibility" in the subprocess PEP
<http://www.python.org/dev/peps/pep-0324/>.
Dennis
Jul 29 '06 #6

di********@gmai l.com wrote:
My server.py looks like this

---------------------------------------------CODE----------------------------------
#!/usr/bin/env python
import socket
import sys
import os

s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
host = ''
port = 2000

s.bind((host,po rt))
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr

while True:
data = conn.recv(10000 00)
if (data == 'MaxSim'):
print 'MaxiSim'
os.system('note pad')
elif (data == 'Driving Sim'):
print 'Driving Sim'
os.system('expl orer')
elif (data == 'SHUTDOWN'):
print 'Shutting down...'
os.system('shut down -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.
As others noted, that's because os.system() blocks.
You have more bugs than that.

The recv() might return "MaxiSimDri ving Sim". It could return
"MaxiS" on one call, and "im" on the next. If the remote side
closes the connection, recv() will keep returning the empty
string, and your program will be stuck in an infinite loop.

Did you understand Faulkner's suggustion? Anyone who connects to
TCP port 2000 can invoke "shutdown -s" (which I assume shuts down
your host).
--
--Bryan

Jul 29 '06 #7
The subprocess module didn't work here. I tried using os.popen(), that
won't help it either.
What I am trying to achieve is that the server daemon is sitting and
listening to command from the client. As client send "MaxSim" it
launches MaxSim.exe and then again waits for subsequent commands.
Support client sends "DrivingSim " it should launch DrivingSim.exe etc.
It does till client sends a "SHUTODWN" message upon which it shuts down
itself.

Any pointers to achieve this more seamlessly.

Every help is greatly appreciated.

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

<untested_cod e>

import subprocess

subprocess.Pope n("notepad")

</untested_code>
Dennis
Aug 10 '06 #8
The recv() might return "MaxiSimDri ving Sim". It could return
"MaxiS" on one call, and "im" on the next. If the remote side
closes the connection, recv() will keep returning the empty
string, and your program will be stuck in an infinite loop.
How to overcome this problem ?
Did you understand Faulkner's suggustion? Anyone who connects to
TCP port 2000 can invoke "shutdown -s" (which I assume shuts down
your host).
I did, anyone who connects to port 2000 might be able to send a
shutdown and close the computer. I am aware that its not the best way
to achieve this but my app runs on a small network without actually
connecting to internet.

Can you give any tips to overcome the above mentioned problem.
--Bryan
Aug 10 '06 #9
I apologize.

subprocess did work for me like a charm I made a mistake in my code.
Appreciate your help.

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

<untested_cod e>

import subprocess

subprocess.Pope n("notepad")

</untested_code>
Dennis
Aug 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2574
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server code put in server. Then web application should be a client-server application. My understanding is that a web application is an application that runs on a browser. But client-server application is not necessary a web application. Please...
18
7384
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure client-side javascript. I forgot to bookmark it, and now I can't find it. Anyone?
7
3372
by: CT | last post by:
Hi, This might seem like a basic question but I have some doubts, please humour me. I have a client-server application using java where each client on each machine needs to directly communicate directly with the database. Do I need a separate db2 connect on each such machine. Please advice.
12
3005
by: ShepardBerry | last post by:
This may be a dumb question, but I'm not finding anything specifically what I'm looking for. Still kind of new to .NET as well. What I'm trying to do that I know I could do in VB6.0/ASP is to create a client side object set some properties and have it run some code. I know that in VB6/asp it was fairly straight forward by creating an ActiveX control, register it and then VBScripting the CreateObject("xxx.xxxx") command and it worked...
3
2660
by: Marc Gravell | last post by:
Kind of an open question on best-practice for smart-client design. I'd really appreciate anyones views (preferably with reasoning, but I'll take what I get...). Or if anybody has any useful links on the subject? (and yes, I have already googled it at length, but still no strong decision) ============= After a long stint of pure-desktop / pure-server applications, I'm currently working on a number of smart-client projects in C# using...
9
2416
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that when I give a path like @"C:\holdfiles\myfile.txt" it looks on the server C drive. How do I pull from the client? Do I need a different class and/or method? Filestream? -- Thanks,
1
1340
by: Frank Millman | last post by:
Hi all I am developing a multi-user business/accounting application. It is coming along nicely :-), though rather slowly :-( I have hit an issue which will require a lot of changes to the code I have written so far, together with an increase in complexity and all the bad things that follow from that. Before I go ahead and make the changes, I thought I would bounce it off the group and see if there is a simpler approach.
2
4726
by: Wimpie van Lingen | last post by:
Hey I have some more questions with regards to Remoting in .NET 2. I'm using TCP with the Binary formatter. My solution consists of 4 projects: - Class Library containing the server classes which Inherits MarshalByRefObject (ok, at this stage it only contains one class... but its gonna grow) - Class Library containing common classes and interfaces that will be shared between all projects. This include interfaces for the server...
11
4889
by: Jeff | last post by:
Hello everyone. I've searched through the archives here, and it seems that questions similar to this one have come up in the past, but I was hoping that I could pick your Pythonic brains a bit. Here's a broad overview of what I need to do: cross-platform, client- side GUI apps that interact with a server backed by a database. I'd also like the possibility of having a web interface for small portions of the app. It will be a fairly...
6
4923
by: 7stud | last post by:
My question pertains to this example: #!/usr/bin/env python import socket, sys, time host = sys.argv textport = sys.argv s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.