-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
executable file
·50 lines (41 loc) · 1.39 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import division
from threading import Thread
import socket
import click
import logging
SERVER_IP = '192.168.99.100'
SITE_URL = 'http://lvivpy.org.ua/'
log = logging.getLogger(__name__)
def handle_client(max_conns):
for connection_num in range(max_conns):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((SERVER_IP, 8888))
req = SITE_URL.encode('utf-8') + b'\n'
client.send(req)
resp = client.recv(1024)
if resp:
result = int(resp)
if result == 200:
log.info('{} is available'.format(SITE_URL))
else:
log.error('{} is not available'.format(SITE_URL))
else:
log.error('Server does not respond')
@click.command()
@click.option('--max-clients', default=1, help='Maximum number of clients')
@click.option('--max-conns', default=1, help='Maximum number of connections per client')
def check_site(max_clients, max_conns):
"""
Test client
Args:
max_clients(int)
max_conns(int)
"""
for client_num in range(max_clients):
Thread(target=handle_client, args=(max_conns,)).start()
if __name__ == '__main__':
logging.basicConfig(level='DEBUG', format="%(threadName)s: %(message)s")
check_site()