-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselect_client.py
More file actions
executable file
·95 lines (70 loc) · 2.49 KB
/
select_client.py
File metadata and controls
executable file
·95 lines (70 loc) · 2.49 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /usr/bin/env python
# Copyright (c) 2016 Dave McCoy ([email protected])
#
# NAME is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# NAME is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NAME; If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import argparse
import socket
#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
NAME = os.path.basename(os.path.realpath(__file__))
DESCRIPTION = "\n" \
"\n" \
"usage: %s [options]\n" % NAME
EPILOG = "\n" \
"\n" \
"Examples:\n" \
"\tSomething\n" \
"\n"
messages = [ 'This is the message. ',
'It will be send ',
'in parts.',
]
server_address = ('localhost', 10001)
def main(argv):
#Parse out the commandline arguments
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=DESCRIPTION,
epilog=EPILOG
)
parser.add_argument("-t", "--test",
nargs=1,
default=["something"])
parser.add_argument("-d", "--debug",
action="store_true",
help="Enable Debug Messages")
args = parser.parse_args()
print "Running Script: %s" % NAME
if args.debug:
print "test: %s" % str(args.test[0])
socks = [socket.socket(socket.AF_INET, socket.SOCK_STREAM),
socket.socket(socket.AF_INET, socket.SOCK_STREAM),
]
for s in socks:
s.connect(server_address)
for message in messages:
for s in socks:
print "%s: Sending: %s" % (s.getsockname(), message)
s.send(message)
#Read reponse on both sockets
for s in socks:
data = s.recv(1024)
print "%s: Received: %s" % (s.getsockname(), data)
if not data:
print "Closing Socket: %s" % s.getsockname()
s.close()
print "Connection to port %s" % server_address
if __name__ == "__main__":
main(sys.argv)