def srv():
    s = snakemq.link.Link()
    container = {"start_time": None, "cli_count": 0, "count": 0}

    def on_connect(conn_id):
        container["cli_count"] += 1
        if container["cli_count"] == CLI_PROC_COUNT * CLI_THR_COUNT:
            container["start_time"] = time.time()
            print "all connected"

    def on_packet_recv(conn_id, packet):
        assert len(packet) == DATA_SIZE
        container["count"] += 1
        if container["count"] >= PACKETS_COUNT * CLI_PROC_COUNT * CLI_THR_COUNT:
            s.stop()

    s.add_listener(("", PORT))
    tr = snakemq.packeter.Packeter(s)
    tr.on_connect = on_connect
    tr.on_packet_recv = on_packet_recv
    s.loop()
    s.cleanup()

    diff = time.time() - container["start_time"]
    count = container["count"]
    print "flow: %.02f MBps, total %i pkts, %i pkts/s" % (
          DATA_SIZE * count / diff / 1024**2, count, count / diff)