<commit_before>import pyperclip
import socket
import threading
import multiprocessing
import time
import sys
import Queue

_PORT = 7890
_SCAN_RANGE = range(2, 255)

class Server(object):
    """docstring for Server"""
    def __init__(self):
        super(Server, self).__init__()
        self.socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._host = "0.0.0.0"
        
    def __call__(self):
        # listen broadcast
        threading.Thread(target=self.recv_broadcast).start()

        # start server
        self.socket_server.bind((self._host, _PORT))
        self.socket_server.listen(5)
        while True:
            conn, address = self.socket_server.accept()
            print address, "connected."
            txt = conn.recv(1024)
            if txt:
                self.txt = txt.strip()
                pyperclip.copy(self.txt)
            else:
                print "txt is empty."

    def recv_broadcast(self):
        addr = ('', _PORT)
        broadcast_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        broadcast_server.bind(addr)
        while True:
            data, addr = broadcast_server.recvfrom(1024)
            print "From addr: '%s', msg: '%s'" % (addr[0], data)
            if "stop" == data:
                break
        broadcast_server.close()

class Client(object):
    """docstring for Client"""
    def __init__(self):
        super(Client, self).__init__()
        self.last_clipboard_txt = pyperclip.paste()
        self.avaliable_hosts = Queue.Queue()
        
    def __call__(self):
        # broadcast me
        self.broadcast_me()
        self.socket_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket_client.connect(("172.18.187.12", _PORT))        
        # listen clipboard change
        while True:
            txt = pyperclip.paste()
            if txt and txt != self.last_clipboard_txt:
                print "clipboard changed: %s -> %s" % (self.last_clipboard_txt, txt)
                self.last_clipboard_txt = txt
                self.socket_client.send(self.last_clipboard_txt)
            time.sleep(1)

    def broadcast_me(self):
        addr = (("255.255.255.255", _PORT))
        broadcast_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        broadcast_client.sendto("cross-paste", addr)
        broadcast_client.close()

if __name__ == '__main__':
    multiprocessing.Process(target=Server()).start()
    multiprocessing.Process(target=Client()).start()<commit_msg>solve 10013 error<commit_after>import pyperclip
import socket
import threading
import multiprocessing
import time
import sys
import Queue

_PORT = 9990
_SCAN_RANGE = range(2, 255)

class Server(object):
    """docstring for Server"""
    def __init__(self):
        super(Server, self).__init__()
        
        
    def __call__(self):
        # listen broadcast
        # start server
        threading.Thread(target=self.recv_broadcast).start()
        self.socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._host = "0.0.0.0"
        self.socket_server.bind((self._host, _PORT))
        self.socket_server.listen(5)
        while True:
            conn, address = self.socket_server.accept()
            print address, "connected."
            txt = conn.recv(1024)
            if txt:
                self.txt = txt.strip()
                pyperclip.copy(self.txt)
            else:
                print "txt is empty."

    def recv_broadcast(self):
        addr = ('', _PORT)
        broadcast_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        broadcast_server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
        broadcast_server.bind(addr)
        while True:
            data, addr = broadcast_server.recvfrom(1024)
            print "From addr: '%s', msg: '%s'" % (addr[0], data)
            if "stop" == data:
                break
        broadcast_server.close()

class Client(object):
    """docstring for Client"""
    def __init__(self):
        super(Client, self).__init__()
        self.last_clipboard_txt = pyperclip.paste()
        
    def __call__(self):
        # broadcast me
        self.broadcast_me()
        self.socket_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = self.socket_client.connect_ex(("172.18.187.12", _PORT))        
        if not result:
            print "connect failed."
            return
        # listen clipboard change
        while True:
            txt = pyperclip.paste()
            if txt and txt != self.last_clipboard_txt:
                print "clipboard changed: %s -> %s" % (self.last_clipboard_txt, txt)
                self.last_clipboard_txt = txt
                self.socket_client.send(self.last_clipboard_txt)
            time.sleep(1)

    def broadcast_me(self):
        addr = (("<broadcast>", _PORT))
        broadcast_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        broadcast_client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
        while True:
            broadcast_client.sendto("cross-paste", addr)
            time.sleep(5)
        broadcast_client.close()

if __name__ == '__main__':
    multiprocessing.Process(target=Server()).start()
    multiprocessing.Process(target=Client()).start()
{'fraction_non_alphanumeric': 0.11102733270499529, 'fraction_numerical': 0.016211121583411876, 'mean_word_length': 2.213809812235009, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '1096329', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1586, 'n_words': 316}