Socket with Python

Juza r0bbie at libero.it
Fri Aug 16 15:56:44 EDT 2002


I'm new with python, i'm in trouble:  this is the code:
SERVER:
import time
import socket
HOST = ''
PORT = 50007
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("Tutto OK")
conn.close()
time.sleep(10)

CLIENT
import time
import socket

HOST = 'localhost'    # The remote host
PORT = 50007              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Mi connetto')
data = s.recv(1024)
s.close()
print 'Received', `data`
time.sleep(10)

My problem is in the SERVER: i need PRINT "*" in sequence until the client
is connected to my HOST, i need a while cicle but i'm very new with the
socket programming; i need while the socket is listen for connection see on
the screen many * in sequence until the client is connected, when it's
connected then stop with *.
Excuse me fr the bad english ^_-





More information about the Python-list mailing list