Basic client/server with sockets
Natan
nvivo at terra.com.br
Mon Feb 10 17:10:35 EST 2003
I'm new to python ans i have a script like this:
---
import socket, time
HOST = 'localhost'
PORT = 5091
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while 1:
input = raw_input("> ")
s.send(input)
try: data = s.recv(1024)
except: data = ''
print data
---
there is a simple server that simply sends back whatever i type in
raw_input, but the problem is that everytime i hit ENTER without
typing anything, the s.recv(n) hangs the server... i noticed that if
the server don't send anything it simply hangs in the recv()
function...
what am i doing wrong? is this the right way to do this? shound't it
just return nothing if the buffer is empty?
by the way... the server code:
---
import socket, time
HOST = 'localhost'
PORT = 5091
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
while 1:
data = conn.recv(32)
conn.send(data)
--
More information about the Python-list
mailing list