#!/usr/bin/env python

# Simple client for the "count characters" protocol. No crypto, anyone
# can sniff the traffic

import logging
import sys
import socket

PORT=4923
MAX=256

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(levelname)s %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S')
if len(sys.argv) != 3:
    logging.error("Usage: %s IPv6-address-of-server message" % sys.argv[0])
    sys.exit(-1)
server = sys.argv[1]
message = sys.argv[2]
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.connect((server, PORT), )
outf = s.makefile('w')
inf = s.makefile('r')
outf.write("%s" % message)
outf.close()
s.shutdown(socket.SHUT_WR)
response = inf.read(MAX)
inf.close()
logging.info("Response was %s" % response)

