Python 3 UDP多线程和多重处理

时间:2017-04-17 14:38:19

标签: python multithreading network-programming python-multiprocessing

我应该在这些文件中进行哪些更改,以使我的服务器处理由一个客户端发送的一系列请求,同时还处理来自多个客户端的多个序列?

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)

1 个答案:

答案 0 :(得分:0)

我没有给出确切的答案,这是一个重复的问题。您的问题的答案如下:Python Socket - Multiple Clientshttps://www.tutorialspoint.com/python/python_multithreading.htm