예제 #1
0
 def stop_receive(self):
     if self.receiving:
         self.log.debug('[MAIN THREAD] Closing data channel. Exiting data client thread')
         self.data_client.stop()
         self.log.info("[MAIN THREAD] Asked server to stop receiving")
         self.receiving = False
         send_data(self.soc_ctrl,STOP_SEND)
     else:
         self.log.warn("[MAIN THREAD] Asked to stop receiving while already receiving")
예제 #2
0
    def import_database(self, input_file, database_name='new_database'):
        self.connect()

        self.data[f'{database_name}'] = helpers.csv_to_dict(input_file,
                                                            sep='\t')
        helpers.send_data(self.server_socket, self.data)

        self.disconnect()
        return
예제 #3
0
 def stop_receive(self):
     if self.receiving:
         self.log.debug(
             '[MAIN THREAD] Closing data channel. Exiting data client thread'
         )
         self.data_client.stop()
         self.log.info("[MAIN THREAD] Asked server to stop receiving")
         self.receiving = False
         send_data(self.soc_ctrl, STOP_SEND)
     else:
         self.log.warn(
             "[MAIN THREAD] Asked to stop receiving while already receiving"
         )
예제 #4
0
파일: client.py 프로젝트: TristHas/debugger
 def stop_record(self, target, name):
     self.log.debug('[MAIN THREAD] Asking server to stop recording')
     msg = MSG_SEP.join([STOP_RECORD, target, name])
     answer = send_data(self.soc_ctrl,msg)
     self.log.info('[MAIN THREAD] Server asked to stop recording')
     if answer == SYNC:
         self.remove_target(target, name)
     else:
         self.log.warn('[MAIN THREAD] Could not remove {} named {} because of server answer'.format(target, name))
예제 #5
0
 def stop_record(self, target, name):
     self.log.debug('[MAIN THREAD] Asking server to stop recording')
     msg = MSG_SEP.join([STOP_RECORD, target, name])
     answer = send_data(self.soc_ctrl, msg)
     self.log.info(
         '[MAIN THREAD] Server asked to stop recording {}'.format(name))
     if answer == SYNC:
         self.remove_target(target, name)
     else:
         self.log.warn(
             '[MAIN THREAD] Could not remove {} named {} because of server answer'
             .format(target, name))
예제 #6
0
파일: client.py 프로젝트: TristHas/debugger
 def resume_training(self):
     if self.paused:
         self.paused = False
         self.log.debug('[MAIN THREAD] Asking server to resume training')
         status = send_data(self.soc_ctrl,RESUME_TRAIN)
         self.log.info('[MAIN THREAD] Server asked to resume training')
         if status == FAIL:
             self.log.error('[MAIN THREAD] Server refused to resume training')
         else:
             self.log.info('[MAIN THREAD] Server has resumed training')
     else:
         self.log.warn("[MAIN THREAD] Asked to resume training while not paused")
예제 #7
0
파일: client.py 프로젝트: TristHas/debugger
 def pause_training(self):
     if not self.paused:
         self.paused = True
         self.log.debug('[MAIN THREAD] Asking server to pause training')
         status = send_data(self.soc_ctrl,PAUSE_TRAIN)
         self.log.info('[MAIN THREAD] Server asked to pause training')
         if status == FAIL:
             self.log.error('[MAIN THREAD] Server refused to pause training')
         else:
             self.log.info('[MAIN THREAD] Server is paused')
     else:
         self.log.warn("[MAIN THREAD] Asked to paused training while already paused")
예제 #8
0
파일: client.py 프로젝트: TristHas/debugger
 def stop_training(self):
     if self.training:
         self.training = False
         self.log.debug('[MAIN THREAD] Asking server to stop training')
         status = send_data(self.soc_ctrl,STOP_TRAIN)
         self.log.info('[MAIN THREAD] Server asked to stop training')
         if status == FAIL:
             self.log.error('[MAIN THREAD] Server refused to stop training')
         else:
             self.log.info('[MAIN THREAD] Server has stopped training')
     else:
         self.log.warn("[MAIN THREAD] Asked to stop training while not training")
예제 #9
0
파일: client.py 프로젝트: TristHas/debugger
 def start_training(self):
     if not self.training:
         self.training = True
         self.log.debug('[MAIN THREAD] Asking server to start training')
         status = send_data(self.soc_ctrl,START_TRAIN)
         self.log.info('[MAIN THREAD] Server asked to start training')
         if status == FAIL:
             self.log.error('[MAIN THREAD] Server refused to start training')
         else:
             self.log.info('[MAIN THREAD] Server is training')
     else:
         self.log.warn("[MAIN THREAD] Asked to start training while already training")
예제 #10
0
 def process_send(self, connection, data):
     targets = self.get_client_targets(connection)
     self.log.debug('[DATA THREAD] targets are {}'.format(targets))
     sub_data = self.get_sub_dict(data, targets)
     self.log.debug('[DATA THREAD] sub_data is  {}'.format(sub_data))
     mess = json.dumps(sub_data)
     self.log.debug('[DATA THREAD] Sending data {}'.format(mess))
     status = send_data(connection, mess)
     if status == '':
         self.receivers.remove(connection)
         self.log.info('[DATA THREAD] connection removed')
     self.log.debug('[DATA THREAD] Data sent')
예제 #11
0
파일: client.py 프로젝트: TristHas/debugger
 def start_receive(self):
     if not self.receiving:
         self.receiving = True
         self.log.debug('[MAIN THREAD] Asking server to start sending')
         status = send_data(self.soc_ctrl,START_SEND)
         self.log.info('[MAIN THREAD] Server asked to start sending')
         if status == FAIL:
             self.log.error('[MAIN THREAD] Client tried to receive but server denied it')
         else:
             self.data_client.start()
             self.log.info('[MAIN THREAD] Client is receiving')
         self.log.debug("[MAIN THREAD] DATA THREAD started")
     else:
         self.log.warn("[MAIN THREAD] Asked to start receiving while already receiving")
예제 #12
0
 def start_receive(self):
     if not self.receiving:
         self.receiving = True
         self.log.debug('[MAIN THREAD] Asking server to start sending')
         status = send_data(self.soc_ctrl, START_SEND)
         self.log.info('[MAIN THREAD] Server asked to start sending')
         if status == FAIL:
             self.log.error(
                 '[MAIN THREAD] Client tried to receive but server denied it'
             )
         else:
             print status
             self.data_client.start()
             self.log.info('[MAIN THREAD] Client is receiving')
         self.log.debug("[MAIN THREAD] DATA THREAD started")
     else:
         self.log.warn(
             "[MAIN THREAD] Asked to start receiving while already receiving"
         )
예제 #13
0
 def stop_all(self):
     self.stop_process()
     send_data(self.soc_ctrl, STOP_ALL)
예제 #14
0
파일: client.py 프로젝트: TristHas/debugger
 def stop_all(self):
     self.stop_process()
     send_data(self.soc_ctrl, STOP_ALL)
예제 #15
0
import socket
import helpers
import json

HOST = '127.0.0.1'
PORT = 61235

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT))
server_socket.listen(3)

data = ''

while True:
    client_socket, address = server_socket.accept()
    print(f'Connection established {address}')

    if data:
        helpers.send_data(client_socket, data)
    else:
        helpers.send_message(client_socket, 'No data available')

    while True:
        message_from_client = helpers.receive(client_socket)
        if not message_from_client:
            client_socket.close()
            print(f'Connection to {address} closed')
            break
        else:
            print(f'{address}: data received')
            # data = json.loads(message_from_client)