File size: 748 Bytes
ddf7ac7
 
4acc1db
ddf7ac7
 
4c3086f
 
ddf7ac7
4c3086f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import socket

HOST = '129.159.146.88'
PORT = 5000

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

    # Remove the finel "." - somehow it stucks the model
    if message.endswith("."):
        message = message.rstrip(".")

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
        client_socket.connect((HOST, 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, please try again')
        finally:
            client_socket.shutdown(socket.SHUT_RDWR)
            client_socket.close()