我应该在这些文件中进行哪些更改,以使我的服务器处理由一个客户端发送的一系列请求,同时还处理来自多个客户端的多个序列?
Client.py
from socket import *
server = "adresa"
port = 12000
clientSocket = socket(family=AF_INET, type=SOCK_DGRAM)
message = input("fjali me te vogla:")
clientSocket.sendto(message.encode("ASCII"),(server,port))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print(modifiedMessage.decode("ASCII"))
Server.py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', serverPort))
print("Serveri eshte i gatshem per pranim te te dhenave")
while True:
message, clientAddress = serverSocket.recvfrom(2048)
print("Mesazhi i pranuar: " + message.decode("ASCII"))
modifiedMessage = message.upper()
serverSocket.sendto(modifiedMessage, clientAddress)
答案 0 :(得分:0)
我没有给出确切的答案,这是一个重复的问题。您的问题的答案如下:Python Socket - Multiple Clients和https://www.tutorialspoint.com/python/python_multithreading.htm