Lawrence Brakmo | d6d4f60 | 2018-01-25 16:14:16 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0 |
| 4 | # |
| 5 | |
| 6 | import sys, os, os.path, getopt |
| 7 | import socket, time |
| 8 | import subprocess |
| 9 | import select |
| 10 | |
| 11 | def read(sock, n): |
| 12 | buf = '' |
| 13 | while len(buf) < n: |
| 14 | rem = n - len(buf) |
| 15 | try: s = sock.recv(rem) |
| 16 | except (socket.error), e: return '' |
| 17 | buf += s |
| 18 | return buf |
| 19 | |
| 20 | def send(sock, s): |
| 21 | total = len(s) |
| 22 | count = 0 |
| 23 | while count < total: |
| 24 | try: n = sock.send(s) |
| 25 | except (socket.error), e: n = 0 |
| 26 | if n == 0: |
| 27 | return count; |
| 28 | count += n |
| 29 | return count |
| 30 | |
| 31 | |
| 32 | serverPort = int(sys.argv[1]) |
| 33 | HostName = socket.gethostname() |
| 34 | |
| 35 | # create active socket |
| 36 | sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) |
| 37 | try: |
| 38 | sock.connect((HostName, serverPort)) |
| 39 | except socket.error as e: |
| 40 | sys.exit(1) |
| 41 | |
| 42 | buf = '' |
| 43 | n = 0 |
| 44 | while n < 1000: |
| 45 | buf += '+' |
| 46 | n += 1 |
| 47 | |
| 48 | sock.settimeout(1); |
| 49 | n = send(sock, buf) |
| 50 | n = read(sock, 500) |
| 51 | sys.exit(0) |