尝试创建客户端服务器端应用程序,其中服务器接收输入消息并进行翻译。
import socket
portNum=6000
serverSocket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
serverSocket.bind((socket.gethostname(),portNum))
print("The server is ready to be used")
def translator(message):
starting = message[0]
if starting == ("a" or "e" or "i" or "u"):
newMessage = message + start + ay
return newMessage
else:
message = message[1:] + starting + "ay"
return message
while True:
message,clientAddress=serverSocket.recvfrom(4096)
newMessage= message.decode()
translator(message)
serverSocket.sendto(newMessage.encode(),clientAddress)
答案 0 :(得分:2)
您永远不会将翻译器的输出分配给变量。尝试更改行
translator(message)
到
newMessage = translator(newMessage)