תשובה אחת
שואל השאלה:
זה הקוד של השרת פייתון גירסא 2.7
import socket
import threading
import time

add= ()
d= ()
i=0

def startconnection ():
time.sleep (0.6)
server_socket.listen (4)
(client_socket,client_address)=server_socket.accept ()
#print "new client has connected"
if i!=0:
sendall ("new client connected",i)
global d
global add
global i
add=add+ (client_address)
d=d+ (client_socket)
i+=1






x=true
def recive (tmp):
time.sleep (0.6)
global x
global i
global d
#print "i am here again working with client number: %d the numbers of connected clients are:%d" % (tmp,i)
data=d (tmp).recv (1024)
if data!= "":
#print data
sendall (data,findplace (d (tmp)))
#print "finish working with client"





def sendall (text,nottosend):
#print "got to sendall"
global i
global d
tp=0
while tp<i:
if tp!=nottosend:
d (tp).send (text)
tp+=1



def run ():
global i
thread = threading.thread (target=startconnection ())
thread.daemon = true
thread.start ()

time.sleep (0.6)
b=0
while i!= 0 and b<=i-1:
time.sleep (0.6)
thread = threading.thread (target=recive (b))
b+= 1


def findplace (client_socket):
global d
i=0
while i<len (d):
if client_socket==d (i):
return i
else:
i+=1
#print "!eror in findplace!"
return -1





if __name__ == '__main__':
server_socket = socket.socket ()
server_socket.bind ( ('127.0.0.1', 231))
while x:
thread = threading.thread (target=run ())
thread.daemon = true
thread.start ()