def METHOD_NAME(conn, addr):
    log('Connection from {0}:{1}'.format(addr[0], str(addr[1])))
    if NODELAY != 0:
        conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    if SNDBUF != 0:
        sndbuf = conn.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
        log('Default SNDBUF %s changed to %s' % (sndbuf, SNDBUF))
        conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, SNDBUF)
    if RCVBUF != 0:
        rcvbuf = conn.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
        log('Default RCVBUF %s changed to %s' % (rcvbuf, RCVBUF))
        conn.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, RCVBUF)
    b = 0
    msgs_out = 0
    msgs_in = 0
    msgs_delta = 0
    msgs_skip = 0
    authenticated = False
    proc_start = time.time()
    while(True):
        if WAIT != -1:
            rs, ws, es = select.select([conn] , [conn], [conn], WAIT)
        else:
            rs, ws, es = select.select([conn] , [conn], [conn])
        if es:
            log("Socket error")
            break;
        if rs:
            data = receive(conn, hdr.size)
            if not data:
                break
            msg_type, msg_id, msg_len = hdr.unpack(data)
            #dump("Got {0}, {1}, {2}".format(msg_type, msg_id, msg_len))
            if msg_type == MsgType.RSP:
                pass
            elif msg_type == MsgType.LOGIN:
                auth = receive(conn, msg_len)
                log("Auth {0}".format(auth))
                # Send auth OK and pin modes
                conn.sendall(hdr.pack(MsgType.RSP, msg_id, MsgStatus.OK))
                conn.sendall(hw("pm", HW_PIN, "in"))
                authenticated = True
            elif msg_type == MsgType.PING:
                log("Ping")
                # Send Pong
                conn.sendall(hdr.pack(MsgType.RSP, msg_id, MsgStatus.OK))
            elif msg_type == MsgType.HW:
                data = receive(conn, msg_len)
                # Print HW messages (just for fun :)
                draw('v')
                dump("> " + " ".join(data.split("\0")))
                msgs_in += 1
                if msgs_out >= MSG_QTY:
                    msgs_delta += 1
            else:
                log("Unknown msg type")
                break
        if ws:
            if authenticated and msgs_out < MSG_QTY:
                conn.sendall(hw("ar", HW_PIN))
                draw('.')
                b = (b + 1) % 256
                msgs_out += 1
            elif msgs_in >= MSG_QTY:
                break
        else:
            msgs_skip += 1
        time.sleep(SLEEP)
    draw("\n")
    log("Time %3.4f" % (time.time() - proc_start))
    log("Sent {0} messages".format(msgs_out))
    log("Recv {0} messages (delta: {1}, skip: {2})".format(msgs_in, msgs_delta, msgs_skip))
    conn.close()