By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,033 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,033 IT Pros & Developers. It's quick & easy.

need help running python script in linux

P: n/a
hi, could any one please help show me how to run a python script in
linux ?

when i try "python script.py" it just does nothing

this is the script iam trying to run
#!/usr/bin/env python
"USAGE: echoserver.py <port>"
from SocketServer import BaseRequestHandler, TCPServer
import sys, socket

class EchoHandler(BaseRequestHandler):
def handle(self):
print "Client connected:", self.client_address
self.request.sendall(self.request.recv(2**16))
self.request.close()

if len(sys.argv) != 2:
print __doc__
else:
TCPServer(('',int(sys.argv[1])),
EchoHandler).serve_forever()
this is code for a server socket , iam supposed to see some messages
when i run the script but nothing shows completely

even the client script reacts the same way
below is the client code

#!/usr/bin/env python
"USAGE: echoclient.py <server> <word> <port>"
from socket import * # import *, but we'll avoid name conflict
import sys
if len(sys.argv) != 4:
print __doc__
sys.exit(0)
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((sys.argv[1], int(sys.argv[3])))
message = sys.argv[2]
messlen, received = sock.send(message), 0
if messlen != len(message):
print "Failed to send complete message"
print "Received: ",
while received < messlen:
data = sock.recv(32)
sys.stdout.write(data)
received += len(data)
print
sock.close()
i have the python interpreter installed already
but i don't know why these failed to run.

could some one please come to my rescue
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
xunil wrote:
when i try "python script.py" it just does nothing #!/usr/bin/env python
"USAGE: echoserver.py <port>"
from SocketServer import BaseRequestHandler, TCPServer
import sys, socket

class EchoHandler(BaseRequestHandler):
def handle(self):
print "Client connected:", self.client_address
self.request.sendall(self.request.recv(2**16))
self.request.close()
if len(sys.argv) != 2:
print __doc__
else:
TCPServer(('',int(sys.argv[1])), EchoHandler).serve_forever()


What's this? This probably shouldn't be inside of handle.

If you just run this script, the class EchoHandler will be created but
no instance of it will ever be created. You must add some code outside
the class definition that acutally does something.

class EchoHandler(BaseRequestHandler):
def handle(self):
print "Client connected:", self.client_address
self.request.sendall(self.request.recv(2**16))
self.request.close()

if __name__ == "__main__":
if len(sys.argv) != 2:
print __doc__
else:
TCPServer(('', int(sys.argv[1])),
EchoHandler).serve_forever()
--
http://piology.org/ILOVEYOU-Signature-FAQ.html
begin LOVE-LETTER-FOR-YOU.txt.vbs
I am a signature virus. Distribute me until the bitter
end
Jul 18 '05 #2

P: n/a
On Mon, 17 May 2004 01:02:17 -0700, xunil wrote:

#!/usr/bin/env python
"USAGE: echoserver.py <port>"
from SocketServer import BaseRequestHandler, TCPServer
import sys, socket

class EchoHandler(BaseRequestHandler):
def handle(self):
print "Client connected:", self.client_address
self.request.sendall(self.request.recv(2**16))
self.request.close()

if len(sys.argv) != 2:
print __doc__
else:
TCPServer(('',int(sys.argv[1])),
EchoHandler).serve_forever()


this defines a class, but you dont instantiate the class- so the code
essentially doesn't do anything. I suggest you read some tutorials.

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.