File size: 1,015 Bytes
ddf7ac7
71acbff
ddf7ac7
 
4c3086f
 
ddf7ac7
9e46021
4c3086f
 
9e46021
 
4c41d5e
4c3086f
 
 
71acbff
e24d15e
 
 
 
 
 
 
 
 
 
 
 
71acbff
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import socket
import config # Here the constants are stored


def getReply(message):
    # Returns a reply from the server

    # Remove the endings that stuck the model
    if message.endswith("."):
        message = message.rstrip(".")
    if message.endswith(" ?"):
        message = message.replace(" ?","?")
    mesage = message.replace(" .",".")

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
        try:
            client_socket.connect((config.HOST, config.PORT))
            client_socket.sendall(message.encode())
            print('Wait...')
            data = client_socket.recv(1024)
            try:
                return data.decode('utf-8')
            except: #sometimes there is a problem with the decoding
                print('Decoding Error')
                return ""
            finally:
                client_socket.shutdown(socket.SHUT_RDWR)
                client_socket.close()
        except:
            return ""

if __name__ == '__main__':
    pass