Esempio n. 1
0
def listen(client=client):
    while True:
        data = client.recv(BUF_SIZE)
        logging.debug(f'Server received {data}')
        if ct.add(json.loads(data)) == 0:
            # Response 'OK' if received data is legal.
            resp = Responses['OKResponse']
            resp['repeat'] = data.decode()
            send(resp, delay=0)
        else:
            # Response 'Fail' if received data is illegal.
            resp = Responses['FailResponse']
            resp['repeat'] = data.decode()
            send(resp, delay=0)
        ct.pprint()
Esempio n. 2
0
def listen(client=client):
    while True:
        data = client.recv(BUF_SIZE)
        logging.debug(f'Client received {data}')
Esempio n. 3
0
import socket
import time
import threading
from profile import IP, PORT, BUF_SIZE, logging

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
client.connect((IP, PORT))


def listen(client=client):
    while True:
        data = client.recv(BUF_SIZE)
        logging.debug(f'Client received {data}')


t = threading.Thread(target=listen)
t.start()

while True:
    s = input('>> ')
    if not s:
        continue
    client.send(f'{s}'.encode())
    logging.debug(f'Client sent {s}')
    time.sleep(1)

Esempio n. 4
0
def send(msg, client=client, delay=1):
    if isinstance(msg, dict):
        msg = json.dumps(msg).encode()
    client.send(msg)
    logging.debug(f'Server send {msg}')
    time.sleep(delay)
Esempio n. 5
0
import time
import json
import socket
import threading
from check_table import CheckTable
from profile import IP, PORT, BUF_SIZE, RuntimeErrors, Responses, logging

ct = CheckTable()

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((IP, PORT))
server.listen(1)
client, address = server.accept()
logging.debug(f'Connection established at {address}')


def send(msg, client=client, delay=1):
    if isinstance(msg, dict):
        msg = json.dumps(msg).encode()
    client.send(msg)
    logging.debug(f'Server send {msg}')
    time.sleep(delay)


def listen(client=client):
    while True:
        data = client.recv(BUF_SIZE)
        logging.debug(f'Server received {data}')
        if ct.add(json.loads(data)) == 0:
            # Response 'OK' if received data is legal.
            resp = Responses['OKResponse']
 def handle(self):
     """ Handle TCP socket request. """
     self.data = self.request.recv(1024).strip()
     logging.debug('Receive {} from {}'.format(self.data,
                                               self.client_address))
     self.do_GET()