<commit_before>import socket


def stopit():
    _send_message('stopit')


def whatsup():
    _send_message('whatsup')


def _send_message(message):
    HOST, PORT = "localhost", 9999

    # Create a socket (SOCK_STREAM means a TCP socket)
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        # Connect to server and send data
        sock.connect((HOST, PORT))
        sock.sendall(message)

        # Receive data from the server and shut down
        received = sock.recv(1024)
    finally:
        sock.close()

    print "Sent:     {}".format(message)
    print "Received: {}".format(received)

    return received
<commit_msg>convert client to twisted<commit_after>from sys import stdout

from twisted.internet import reactor
from twisted.internet.protocol import Factory, Protocol
from twisted.internet.endpoints import TCP4ClientEndpoint


class HeyProtocol(Protocol):
    def sendMessage(self, message):
        self.transport.write(message)
        stdout.write("Sent:     {}\n".format(message))

    def dataReceived(self, data):
        stdout.write("Received: {}\n".format(data))
        self.transport.loseConnection()
        reactor.stop()


class HeyFactory(Factory):
    def buildProtocol(self, addr):
        return HeyProtocol()


def stopit():
    _send_message('stopit')


def whatsup():
    _send_message('whatsup')


def _build_message_callback(message):
    def protocol_callback(p):
        p.sendMessage(message)

    return protocol_callback


def _send_message(message):
    HOST, PORT = "localhost", 9999

    point = TCP4ClientEndpoint(reactor, HOST, PORT)
    d = point.connect(HeyFactory())
    d.addCallback(_build_message_callback(message))
    reactor.run()

{'fraction_non_alphanumeric': 0.10755813953488372, 'fraction_numerical': 0.00813953488372093, 'mean_word_length': 3.4128205128205127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3545295', 'n_tokens_mistral': 533, 'n_tokens_neox': 496, 'n_words': 124}