<commit_before>import json
import socket
import hashlib


def send_msg(ip, port, message):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))
    try:
        sock.sendall(message)
        response = sock.recv(1024)
        print "Received: {}".format(response)
    finally:
        sock.close()


def send_offer(ip, port, offer):
    message = json.dumps(offer)
    send_msg(ip, port, message)<commit_msg>send_msg now returns response. Add handling for trade messages client-side.<commit_after>import json
import socket
import hashlib


from orderbook import trade_offer, create_trade


def send_msg(ip, port, message):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))
    try:
        sock.sendall(message)
        response = sock.recv(1024)
        print "Received: {}".format(response)
    finally:
        sock.close()
    return response


def send_offer(ip, port, offer):
    message = json.dumps(offer)
    return send_msg(ip, port, message)


def handle_response(response):
    response = json.loads(response)
    if response['type'] == 'trade':
        return handle_trade(response)
    return "Nothing"

def handle_trade(trade):
    id = trade['trade-id'].split(';')[0]

    return create_trade(
        id = id,
        quantity=trade['quantity'],
        trade_id = trade['trade-id']
    )
{'fraction_non_alphanumeric': 0.11939218523878437, 'fraction_numerical': 0.006512301013024602, 'mean_word_length': 3.229357798165138, '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': '1725726', 'n_tokens_mistral': 454, 'n_tokens_neox': 425, 'n_words': 104}