コード例 #1
0
ファイル: test_discovery.py プロジェクト: yasusii/networkzero
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
ファイル: test_discovery.py プロジェクト: tjguk/networkzero
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
ファイル: test_discovery.py プロジェクト: yasusii/networkzero
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
ファイル: test_discovery.py プロジェクト: tjguk/networkzero
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
ファイル: test_discovery.py プロジェクト: yasusii/networkzero
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
ファイル: test_discovery.py プロジェクト: tjguk/networkzero
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
ファイル: chat.py プロジェクト: funkyHat/zerochat
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
ファイル: test_discovery.py プロジェクト: yasusii/networkzero
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
ファイル: test_discovery.py プロジェクト: yasusii/networkzero
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
ファイル: test_discovery.py プロジェクト: yasusii/networkzero
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)
コード例 #12
0
import networkzero as nw0

# import shell

print(nw0.discover_all())
コード例 #13
0
ファイル: test_discovery.py プロジェクト: tjguk/networkzero
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
ファイル: test_discovery.py プロジェクト: tjguk/networkzero
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
ファイル: test_discovery.py プロジェクト: tjguk/networkzero
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:
コード例 #17
0
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()