Пример #1
0
def test_unadvertise(beacon):
    ttl_s = 2
    service = uuid.uuid4().hex
    address = nw0.advertise(service, ttl_s=ttl_s)
    assert [service, address] in nw0.discover_all()
    nw0.discovery._unadvertise(service)
    time.sleep(1 + ttl_s)
    assert [service, address] not in nw0.discover_all()
Пример #2
0
def test_unadvertise(beacon):
    ttl_s = 2
    service = uuid.uuid4().hex
    address = nw0.advertise(service, ttl_s=ttl_s)
    assert [service, address] in nw0.discover_all()
    nw0.discovery._unadvertise(service)
    time.sleep(1 + ttl_s)
    assert [service, address] not in nw0.discover_all()
Пример #3
0
def test_advertise_ttl(beacon):
    service = uuid.uuid4().hex
    ttl_s = 5
    address = nw0.advertise(service, ttl_s=ttl_s)
    assert [service, address] in nw0.discover_all()
    #
    # Stop advert broadcast for long enough that any
    # stale ones will be expired
    #
    nw0.discovery._pause()
    try:
        time.sleep(1 + ttl_s)
        assert [service, address] not in nw0.discover_all()
    finally:
        nw0.discovery._resume()
Пример #4
0
def test_advertise_ttl(beacon):
    service = uuid.uuid4().hex
    ttl_s = 5
    address = nw0.advertise(service, ttl_s=ttl_s)
    assert [service, address] in nw0.discover_all()
    #
    # Stop advert broadcast for long enough that any
    # stale ones will be expired
    # 
    nw0.discovery._pause()
    try:
        time.sleep(1 + ttl_s)
        assert [service, address] not in nw0.discover_all()
    finally:
        nw0.discovery._resume()
Пример #5
0
def test_discover_all(beacon):
    service1 = uuid.uuid4().hex
    address1 = nw0.advertise(service1)
    service2 = uuid.uuid4().hex
    address2 = nw0.advertise(service2)
    services = dict(nw0.discover_all())
    assert services == {service1: address1, service2: address2}
Пример #6
0
def test_discover_all(beacon):
    service1 = uuid.uuid4().hex
    address1 = nw0.advertise(service1)
    service2 = uuid.uuid4().hex
    address2 = nw0.advertise(service2)
    services = dict(nw0.discover_all())
    assert services == {service1:address1, service2:address2}
Пример #7
0
def main():

    username = input("Please enter your username: "******"zerochat_" + username)

    oldchats = {}
    while True:

        chats = {name:address for name, address in nw0.discover_all() if name.startswith("zerochat_")}
        if chats.keys() != oldchats.keys():
            print("New users:")
            print(chats)

        rlist, wlist, elist = select.select([sys.stdin], [], [], 0.1)
        if rlist:
            recipient = sys.stdin.readline().rstrip()
            msg = input("Message:").rstrip()
            print("\x1b[31;m[%s] %s\x1b[0m" % (recipient, msg))

            recipient_service = nw0.discover("zerochat_" + recipient)
            nw0.send_message_to(recipient_service, msg)


        received_msg = nw0.wait_for_message_from(address, wait_for_s=0, autoreply=True)
        if received_msg is not None:
            print("Got message: %s" % received_msg)

        oldchats = chats
Пример #8
0
def test_advertise_no_address(beacon):
    service = uuid.uuid4().hex
    address = nw0.advertise(service)
    assert is_valid_address(address)
    assert [service, address] in nw0.discover_all()
Пример #9
0
def test_advertise_full_address(beacon):
    service = uuid.uuid4().hex
    service_address = "192.168.1.1:1234"
    address = nw0.advertise(service, service_address)
    assert address == service_address
    assert [service, address] in nw0.discover_all()
Пример #10
0
def test_advertise_no_port(beacon):
    service = uuid.uuid4().hex
    address = nw0.advertise(service)
    assert is_valid_address(address, port_range=nw0.config.DYNAMIC_PORTS)
    assert [service, address] in nw0.discover_all()
Пример #11
0
import networkzero as nw0

services = nw0.discover_all()
print("Services:", services)
import networkzero as nw0

# import shell

print(nw0.discover_all())
Пример #13
0
def test_advertise_full_address(beacon):
    service = uuid.uuid4().hex
    service_address = "192.168.1.1:1234"
    address = nw0.advertise(service, service_address)
    assert address == service_address
    assert [service, address] in nw0.discover_all()
Пример #14
0
def test_advertise_no_port(beacon):
    service = uuid.uuid4().hex
    address = nw0.advertise(service)
    assert is_valid_address(address, port_range=nw0.config.DYNAMIC_PORTS)
    assert [service, address] in nw0.discover_all()
Пример #15
0
def test_advertise_no_address(beacon):
    service = uuid.uuid4().hex
    address = nw0.advertise(service)
    assert is_valid_address(address)
    assert [service, address] in nw0.discover_all()
Пример #16
0
from Questions import Question 
from time import time, sleep
import random

players = []
player_addresses = []
MAX_PLAYERS = 2

# Open the quiz server and bind it to a port - creating a socket
quiz_server = nwz.advertise('Quiz')
player_ID = 0

# Search for messages from participants until roster is full
while len(players) < MAX_PLAYERS:
    # Poll the server checking for requests from participants
    connections = nwz.discover_all()
    #print(connections)
    # If a message has been recieved
    if len(connections) > 0:
        for c in connections:
            # Capture the address for the connection to the quiz client
            if "Quiz Participant" in c[0] and c[1] not in player_addresses:
                print(connections)
                nwz.send_news_to(quiz_server, "Information", "Player acknowledged" + c[1])
                conn = nwz.discover(c[0])
                response = nwz.send_message_to(conn, player_ID)
                nwz.send_reply_to(conn)
                players.append(Player(player_ID, c[1], conn))
                player_addresses.append(c[1])
                player_ID += 1
    else:
import networkzero as nw0

services = dict(nw0.discover_all())
Пример #18
0
def test_advertise_no_address(beacon):
    service = uuid.uuid1().hex
    address = nw0.advertise(service)
    assert is_valid_address(address)
    assert (service, address) in nw0.discover_all()
    nw0.discovery.stop_beacon()