7 parser = argparse.ArgumentParser(description=
'Simple socket client')
8 parser.add_argument(
"--port", default=8080, type=int)
9 parser.add_argument(
"--udp", action=
"store_true")
10 parser.add_argument(
"--ip", default=
"127.0.0.1")
11 args = parser.parse_args()
13 print(
"connecting to ", (args.ip, args.port))
16 server =
socket(AF_INET, SOCK_STREAM)
17 server.connect((args.ip, args.port))
19 server =
socket(AF_INET, SOCK_DGRAM)
21 data = raw_input(
'> ')
24 packer = struct.Struct(
"!%ds" % len(data))
25 data = packer.pack(data)
26 print(
"sending", packer.size * 8,
"bits")
30 server.sendto(data, (args.ip, args.port))