本文整理汇总了Python中Message.enc_chal方法的典型用法代码示例。如果您正苦于以下问题:Python Message.enc_chal方法的具体用法?Python Message.enc_chal怎么用?Python Message.enc_chal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.enc_chal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sock_loop
# 需要导入模块: import Message [as 别名]
# 或者: from Message import enc_chal [as 别名]
def sock_loop(s, c):
q = Queue()
send_threads = []
while not c.quitf:
# check the Queue for data(s) to send
while True:
# keep looping until the queue is empty
try:
rcv_msg = q.get_nowait()
for thread in send_threads:
thread.q.put(rcv_msg)
except queue.Empty:
# the queue has been emptied
break
# check the Carrier for data to send
if c.send_str:
for thread in send_threads:
thread.q.put(c.send_str)
c.send_str = None
# obtain a new socket connection
# wait to accept a connection - NON blocking call
try:
s.setblocking(False)
conn, addr = s.accept()
s.setblocking(True)
if conn and addr:
print(addr[0] + ':' + str(addr[1]) + " has connected.")
print("Authenticating sock...")
challenge = Message.random_chal()
conn.send(challenge)
print("Sent request...")
while True:
try:
response = conn.recv(32)
if response:
break
except BlockingIOError:
time.sleep(0.1)
if Message.enc_chal(challenge, PASSWORD) == response:
print("Client authenticated successfully.")
sock_recv_thread = threading.Thread(target=sock_recv_server, args=(conn, c, q))
sock_recv_thread.daemon = True
sock_recv_thread.start()
sock_send_thread = SockSendThread(args=(conn, c))
sock_send_thread.daemon = True
sock_send_thread.start()
send_threads.append(sock_send_thread)
conn.send(Message.Message('Welcome to the server.', author='Server').encrypt(PASSWORD))
else:
# Client cannot authenticate. Disconnect it
print("Client has incorrect password. Disconnecting client...")
conn.send(b'\mq')
conn.close()
except Exception as e:
if e.errno == 11:
# we don't got it yet
time.sleep(0.1)
pass
if e.errno == 35:
time.sleep(0.1)
pass
else:
print("ERROR:", e)
示例2: popup_message
# 需要导入模块: import Message [as 别名]
# 或者: from Message import enc_chal [as 别名]
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
try:
sock.connect((host, port))
except ConnectionRefusedError:
popup_message("Server refused connection. Check that server is running.", wait_button=True)
end_prog(1)
except ConnectionError:
popup_message("Server not found. Check server address.", wait_button=True)
end_prog(1)
popup_message("Connecting to " + str(host) + " on port " + str(port) + "...")
# Wait for challenge from server and respond for authentication
challenge = sock.recv(32)
response = Message.enc_chal(challenge, PASSWORD)
sock.send(response)
# Disable blocking
sock.setblocking(True)
kill = False
sock_queue = Queue(0)
sock_recv_thread = threading.Thread(target=sock_recv_server, args=(sock, kill, sock_queue))
sock_recv_thread.setDaemon(True)
sock_recv_thread.start()
popup_message("Successfully connected to server.")
# Create the window for accepting input
input_window = newwin(1, COLS, LINES - 1, 0)