server question
vin
fractal97 at hotmail.com
Sat Aug 11 14:07:44 EDT 2001
Ok pasting of the error was wrong I did it last night while being very
tired.
here is the code again
import socket
def start_server(PORT):
HOST = '' # Symbolic name meaning the local host
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data : break
conn.send(eval(data))
conn.close()
now I telnet to the machine and type 5*6 and then 'enter' as follows
$ telnet 127.0.0.1 8484
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
5*6 [enter]
and server responds ....
>>> import server
>>> server.start_server(8484)
Connected by ('127.0.0.1', 1032)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "server.py", line 13, in start_server
conn.send(eval(data))
File "<string>", line 1
5*6
^
SyntaxError: invalid syntax
Now I know that conn.recv() should return a string, but it seems that I
can't evaluate that string with eval. You can print 'data' but not do
eval(data) it always reports syntax error. Why?
Thanks for the references I'll look into it.
Vin
More information about the Python-list
mailing list