本文整理匯總了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)