예제 #1
0
def backend():
    s = NitroSocket()
    s.bind("tcp://127.0.0.1:4444")

    while True:
        fr = s.recv()
        out = NitroFrame("mega" + fr.data)
        s.reply(fr, out)
예제 #2
0
def broadcaster():
    print 'three!'
    s = NitroSocket()
    s.bind("tcp://127.0.0.1:4444")
    s.sub("foo")
    sleep(0.4)

    print 'moving on!'

    assert s.pub("food", NitroFrame("hungry?")) == 1
    assert s.pub("fool", NitroFrame("silly?")) == 2
    assert s.pub("barn", NitroFrame("moo!")) == 0
    sleep(0.5)
    print " ~~ Everyone wins! ~~"
예제 #3
0
from pynitro import NitroSocket, NitroFrame
import time
import select

ns = NitroSocket(want_eventfd=True)
ns.bind("tcp://127.0.0.1:7723")

select.select([ns], [], [])
fr = ns.recv(NitroSocket.NOWAIT)
print fr
print fr.data
ns.send(NitroFrame("my only sunshine"))
select.select([ns], [], [])
fr = ns.recv(NitroSocket.NOWAIT)
print fr
print fr.data
ns.send(NitroFrame("when skies are gray"))
time.sleep(4)
예제 #4
0
    global done
    s = NitroSocket()
    s.connect("tcp://127.0.0.1:4445")

    for x in xrange(100000):
        fr = NitroFrame(uniq + str(x))
        s.send(fr)
        fr = s.recv()
        assert(fr.data == "mega" + uniq + str(x))

    print uniq, "done!"
    done += 1

proxy_sock_f = NitroSocket()
proxy_sock_b = NitroSocket()
proxy_sock_f.bind("tcp://127.0.0.1:4445")
proxy_sock_b.connect("tcp://127.0.0.1:4444")

thread.start_new_thread(backend, ())
sleep(0.5)
thread.start_new_thread(proxy_down, (proxy_sock_f, proxy_sock_b))
thread.start_new_thread(proxy_up, (proxy_sock_f, proxy_sock_b))
sleep(0.5)
map(lambda id: thread.start_new_thread(sender, (id,)),
    ["dog", "cat", "mouse", "rat"])

while done < 4:
    sleep(0.2)

print ".. All finished"