예제 #1
0
def test_zpoller(verbose=False):

    ctx = zctx.new()

    # Create a few sockets
    vent = zsocket.new(ctx, zmq.PUSH);
    rc = zsocket.bind(vent, "tcp://*:9000")
    assert rc != -1, "vent bind error"
    sink = zsocket.new(ctx, zmq.PULL)
    rc = zsocket.connect(sink, "tcp://localhost:9000");
    assert rc != -1, "sink connect error"
    bowl = zsocket.new(ctx, zmq.PULL)
    dish = zsocket.new(ctx, zmq.PULL)

    # Set-up poller
    poller = zpoller.new(bowl, sink, dish)
    assert poller, "poller create error"

    zstr.send(vent, "Hello, World")

    # We expect a message only on the sink
    which = zpoller.wait(poller, 1000)

    assert which == sink, "expected message on sink only"
    assert not zpoller.expired(poller), "unexpected poll timer exipiry"
    assert not zpoller.terminated(poller), "unexpected poller termination (interrupted)"

    message = zstr.recv(which)
    assert message == "Hello, World", "unexpected message recevied"

    # Destroy poller and context
    del poller
    del ctx
예제 #2
0
def s_can_connect(server, client):
    global PORT_NBR
    rc = zsocket.bind(server, "tcp://*:{}".format(PORT_NBR))
    assert rc == PORT_NBR
    rc = zsocket.connect(client, "tcp://127.0.0.1:{}".format(PORT_NBR))
    assert rc == 0

    zstr.send(server, "Hello World")

    poller = zpoller.new(client)
    success = zpoller.wait(poller, 100) == client
    del poller

    rc = zsocket.unbind(server, "tcp://*:{}".format(PORT_NBR))
    assert rc != -1
    rc = zsocket.disconnect(client, "tcp://127.0.0.1:{}".format(PORT_NBR))
    assert rc != -1
    PORT_NBR += 1
    return success
예제 #3
0
파일: test_zauth.py 프로젝트: minrk/pyczmq
def s_can_connect(server, client):
    global PORT_NBR
    rc = zsocket.bind(server, "tcp://*:{0}".format(PORT_NBR))
    assert rc == PORT_NBR
    rc = zsocket.connect(client, "tcp://127.0.0.1:{0}".format(PORT_NBR))
    assert rc == 0

    zstr.send(server, "Hello World")

    poller = zpoller.new(client)
    success = zpoller.wait(poller, 100) == client
    del poller

    rc = zsocket.unbind(server, "tcp://*:{0}".format(PORT_NBR))
    assert rc != -1
    rc = zsocket.disconnect(client, "tcp://127.0.0.1:{0}".format(PORT_NBR))
    assert rc != -1
    PORT_NBR += 1
    return success