<commit_before>__author__ = 'calvin'

import time
import json
import socket
from threading import Thread

def run(port, cmds):
    HOST = ''
    DISCOVER_PORT = 1213

    def communicate(sock, cmd):
        """
        Send a command and print it's response
        :param cmd:
        :return:
        """
        if not isinstance(cmd, dict):
            cmd()
        else:
            sock.send(json.dumps(cmd))
            time.sleep(1)
            print sock.recv(1024)

    # Connect to the discoverer socket
    print 'Opening discoverer port'
    discover_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    discover_socket.connect((HOST, DISCOVER_PORT))

    # Ask the process to create a new socket for communication
    print 'Requesting new socket'
    response = communicate(discover_socket, {'command': 'ACT', 'trackable': '', 'action': 'new_connection', 'args': (port,)})
    print response
    print 'Closing discoverer port'<commit_msg>Change HOST to 127.0.0.1 for compatibility on Windows<commit_after>__author__ = 'calvin'

import time
import json
import socket
from threading import Thread

def run(port, cmds):
    HOST = '127.0.0.1'
    DISCOVER_PORT = 1213

    def communicate(sock, cmd):
        """
        Send a command and print it's response
        :param cmd:
        :return:
        """
        if not isinstance(cmd, dict):
            cmd()
        else:
            sock.send(json.dumps(cmd))
            time.sleep(1)
            print sock.recv(1024)

    # Connect to the discoverer socket
    print 'Opening discoverer port'
    discover_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    discover_socket.connect((HOST, DISCOVER_PORT))

    # Ask the process to create a new socket for communication
    print 'Requesting new socket'
    response = communicate(discover_socket, {'command': 'ACT', 'trackable': '', 'action': 'new_connection', 'args': (port,)})
    print response
    print 'Closing discoverer port'
{'fraction_non_alphanumeric': 0.10308236483072258, 'fraction_numerical': 0.015159171298635674, 'mean_word_length': 2.7218045112781954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '576194', 'n_tokens_mistral': 598, 'n_tokens_neox': 576, 'n_words': 175}