本文整理汇总了Python中Message.random_chal方法的典型用法代码示例。如果您正苦于以下问题:Python Message.random_chal方法的具体用法?Python Message.random_chal怎么用?Python Message.random_chal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.random_chal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sock_loop
# 需要导入模块: import Message [as 别名]
# 或者: from Message import random_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)