我正在使用客户机/服务器程序创建一个Caesar密码程序。客户端将输入消息和密钥,服务器将返回密码文本。这是我的服务器代码:
import socket
def getCaesar(message, key):
cipher = ""
for i in message:
char = message[i]
# Encrypt uppercase characters
if (char.isupper()):
cipher += chr((ord(char) + key-65) % 26 + 65)
# Encrypt lowercase characters
else:
cipher += chr((ord(char) + key - 97) % 26 + 97)
return cipher
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host=socket.gethostname()
port=4000
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host,port))
s.listen(5)
print("Listenting for requests")
while True:
s,addr=s.accept()
print("Got connection from ",addr)
print("Receiving...")
message,key=s.recv(1024)
resp=getCaesar(message, key)
s.send(resp)
s.close()
错误消息调用以下行:s.send(message,key)并显示以下错误:
OSError:[WinError 10045]引用的对象类型不支持尝试的操作。这个错误是什么意思?在
我的客户代码:
^{pr2}$
请参阅帮助(套接字.send)公司名称:
因此,行}被解释为标志,而不是{}和{}。尝试分别发送}。别忘了把它们分开。在
s.send(message, key)
可能不是您预期的方式:它只发送message
,其中{message
和{相关问题 更多 >
编程相关推荐