我正在尝试从客户端向服务器发送消息,但服务器未收到任何信息。服务器可以将消息正确发送到客户端,但是客户端无法发送消息。
我已经尝试使用str()并更改填充的块大小。在这一点上,我正在尝试解决所有问题,然后再失去所有头发。
我的客户程序 ...
# Client receives a message and send it to the client
encryptedNameQ = clientSocket.recv(2048)
padNameQ = cipher.decrypt(encryptedNameQ)
nameQ = unpad(padNameQ, 16).decode("ascii")
#print(nameQ) this works and prints the correct thing
# Client send name to the server
nameA = input(nameQ + "\n\nAnswer: ")
name = cipher.encrypt(pad(nameA.encode("ascii"), 16))
print(name) # This works and the message is encrypted
clientSocket.send(name)
...
我的服务器程序 ...
# Server send encypted message to the client
welcomeMsg = cipher.encrypt(pad("Welcome to examination System\nWhat is your name? ".encode("ascii"), 16))
#print(welcomeMsg)
connectionSocket.send(welcomeMsg)
# Server receives client message, decodes it
nameMsg = connectionSocket.recv(2048) #not getting anything
print("Encrypted message recived: " + nameMsg)
padName = cipher.decrypt(nameMsg)
# Unpad message
name = unpad(padName, 16).decode("ascii")
print("Decrypted message recived: " + name)
...
欢迎消息正在由服务器发送,并由客户端正确接收,但是名称未由服务器发送,我也不知道为什么。它不打印服务器程序中的任何行,但已在客户端程序中打印填充名称。代码基本上是相同的,所以我不知道出了什么问题。