Пример #1
0
def client(hostname, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((hostname, port))
    s.sendall(lancelot.qa[0][0])
    answer1 = lancelot.recv_until(s, b'.')  # answers end with '.'
    s.sendall(lancelot.qa[1][0])
    answer2 = lancelot.recv_until(s, b'.')
    s.sendall(lancelot.qa[2][0])
    answer3 = lancelot.recv_until(s, b'.')
    s.close()
    print(answer1)
    print(answer2)
    print(answer3)
def client(hostname, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((hostname, port))
    s.sendall(lancelot.qa[0][0])
    answer1 = lancelot.recv_until(s, '.')  # answers end with '.'
    s.sendall(lancelot.qa[1][0])
    answer2 = lancelot.recv_until(s, '.')
    s.sendall(lancelot.qa[2][0])
    answer3 = lancelot.recv_until(s, '.')
    s.close()
    print answer1
    print answer2
    print answer3
def handle_client(client_sock):
    try:
        while True:
            question = lancelot.recv_until(client_sock, "?")
            answer = lancelot.qadict[question]
            client_sock.sendall(answer)
    except EOFError:
        client_sock.close()
Пример #4
0
def handle_client(client_sock):
    try:
        while True:
            question = lancelot.recv_until(client_sock, b'?')
            answer = lancelot.qadict[question]
            client_sock.sendall(answer)
    except EOFError:
        client_sock.close()
Пример #5
0
 def test_dialog(self):
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     sock.connect((SERVER_HOST, lancelot.PORT))
     for i in range(10):
         question, answer = lancelot.qa[i % len(launcelot.qa)]
         sock.sendall(question)
         reply = lancelot.recv_until(sock, '.')
         self.assertEqual(reply, answer)
     sock.close()
Пример #6
0
def handle_client(client_sock):
    """Responds to client until connection closed"""
    try:
        while True:
            question = lancelot.recv_until(client_sock, '?')
            answer = lancelot.qadict[question]
            client_sock.sendall(answer.encode("utf-8"))
    except EOFError:
        client_sock.close()