請告訴我我的服務器代碼有什麼問題。它不能同時爲兩個客戶端工作。它僅爲我首先運行的客戶端運行。我是python和套接字編程的新手。請在這裏幫助我。服務器不適用於多個客戶端
import socket
import sys
import thread
import time
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the address given on the command line
server_address = ('127.0.0.1', 10001)
data = " ".join(sys.argv[1:])
sock.bind(server_address)
print >>sys.stderr, 'starting up on %s port %s' % sock.getsockname()
sock.listen(1)
connection, client_address = sock.accept()
def my(threadName , delay):
while True:
print >>sys.stderr, 'waiting for a connection'
try:
print >>sys.stderr, 'client connected:', client_address
while True:
data = connection.recv(16)
print >>sys.stderr, 'received "%s"' % data
a=['a' ,'e', 'i' , 'o' , 'u']
for i in data:
if i in a:
data = data.replace(i, '')
data=data.upper()
print data
print'\nUpper case string:'
if data:
connection.sendall(data)
else:
break
finally:
connection.close()
thread.start_new_thread(my , ("Thread-1" , 8,))
thread.start_new_thread(my , ("Thread-2" , 10,))