summaryrefslogtreecommitdiffstats
path: root/lab_control/connection/tcp_connection.py
blob: 6af710c47ef213cc6592b0c127683df3f21497af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import socket

class TCPConnection:
    def __init__(self, ip: str, port: int):
        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._socket.connect((address, port))

    def configure(self, config: dict) -> None:
        self._socket.settimeout(parameters["timeout"])

    def send(self, request, responseExpected=True):
        self._socket.sendall(request.encode())

        if responseExpected:
            try:
                response = self._socket.recv(4096).decode()
            except TimeoutError:
                response = None
            return response
        
    def checkConfiguration(self) -> None:
        pass