server question
Roman Suzi
rnd at onego.ru
Sat Aug 11 02:27:35 EDT 2001
On Sat, 11 Aug 2001, vin wrote:
>I am trying to evaluate a string with a simple server and send the result
>back but I can't get it to work.
>
>import socket
>
>def start_server(PORT):
> HOST = ' ' # Symbolic name meaning the local host
Hmmm... I always thought this supposed to be ''
> 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()
>
>When I send "5*6" the server chrashes. ....
>
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "server.py", line 13, in start_server
> print 'Evaluated', eval(data)
> File "<string>", line 1
> 5*6
> ^
>SyntaxError: invalid syntax
>
>How can I get it to work?
Maybe, you can try to
string.strip expression before evaluation?
>Thanks
Sincerely yours, Roman Suzi
--
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Saturday, August 11, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "After a hard day, it's nice to come home to a warm cat." _/
More information about the Python-list
mailing list