Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
lsbaws/part3/client3.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (45 sloc)
1.46 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################### | |
# Test client - client3.py # | |
# # | |
# Tested with Python 2.7.9 & Python 3.4 on Ubuntu 14.04 & Mac OS X # | |
##################################################################### | |
import argparse | |
import errno | |
import os | |
import socket | |
SERVER_ADDRESS = 'localhost', 8888 | |
REQUEST = b"""\ | |
GET /hello HTTP/1.1 | |
Host: localhost:8888 | |
""" | |
def main(max_clients, max_conns): | |
socks = [] | |
for client_num in range(max_clients): | |
pid = os.fork() | |
if pid == 0: | |
for connection_num in range(max_conns): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect(SERVER_ADDRESS) | |
sock.sendall(REQUEST) | |
socks.append(sock) | |
print(connection_num) | |
os._exit(0) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description='Test client for LSBAWS.', | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | |
) | |
parser.add_argument( | |
'--max-conns', | |
type=int, | |
default=1024, | |
help='Maximum number of connections per client.' | |
) | |
parser.add_argument( | |
'--max-clients', | |
type=int, | |
default=1, | |
help='Maximum number of clients.' | |
) | |
args = parser.parse_args() | |
main(args.max_clients, args.max_conns) |