def client(host, port): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.sendall(launcelot.qa_pair[0][0].encode()) answer1 = launcelot.recv_until(s, '.') s.sendall(launcelot.qa_pair[1][0].encode()) answer2 = launcelot.recv_until(s, '.') s.sendall(launcelot.qa_pair[2][0].encode()) answer3 = launcelot.recv_until(s, '.') print(answer1, answer2, answer3) s.close()
def client(hostname, port): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((hostname, port)) s.sendall(launcelot.qa[0][0]) answer1 = launcelot.recv_until(s, '.') s.sendall(launcelot.qa[1][0]) answer2 = launcelot.recv_until(s, '.') s.sendall(launcelot.qa[2][0]) answer3 = launcelot.recv_until(s, '.') s.close() print answer1 print answer2 print answer3
def handle_client(sock): try: while True: q = launcelot.recv_until(sock, '?') a = launcelot.qa_dict[q] sock.sendall(a.encode()) except EOFError as e: sock.close()
def handle_client(client_sock): try: while True: question = launcelot.recv_until(client_sock, '?') answer = launcelot.qadict[question] client_sock.sendall(answer) except EOFError: client_sock.close()
def handle_client (client_sock): try: while True: question = launcelot.recv_until (client_sock, '?') answer = launcelot.qadict.get (question, "I don't understand your question.") client_sock.sendall (answer) except (EOFError, socket.error): client_sock.close()
def handle_client(sock): try: while True: q = launcelot.recv_until(sock, '?') a = launcelot.qa_dict[q] print('Question is:', q, "answer is:", a) sock.sendall(a.encode()) except EOFError as e: sock.close()
def test_dialog(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((SERVER_HOST, launcelot.PORT)) for i in range(10): q, a = launcelot.qa_pair[i % len(launcelot.qa_pair)] sock.sendall(q) reply = launcelot.recv_until(sock, '.') self.assertEqual(reply, a) sock.close()
def test_dialog (self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect ((SERVER_HOST, launcelot.PORT)) for i in range(3): for k, v in launcelot.qadict.items(): sock.sendall (k) reply = launcelot.recv_until(sock, '.') self.assertEqual (reply, v) sock.close()
def client (hostname, port): s = socket.socket (socket.AF_INET, socket.SOCK_STREAM) s.connect ((hostname, port)) answers=[] for k in launcelot.qadict.keys(): s.sendall (k) a = launcelot.recv_until (s, '.') answers.append(a) s.close() for a in answers: print a