Skip to content

Commit

Permalink
Rewrite examples/client_ws.py
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Dec 8, 2017
1 parent feaf021 commit 57edaca
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions examples/client_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
from asyncio import selectors


def start_client(loop, url):
async def start_client(loop, url):
name = input('Please enter your name: ')

# send request
ws = yield from aiohttp.ws_connect(url, autoclose=False, autoping=False)

# input reader
def stdin_callback():
line = sys.stdin.buffer.readline().decode('utf-8')
Expand Down Expand Up @@ -51,7 +48,9 @@ async def dispatch():

break

yield from dispatch()
# send request
async with aiohttp.ws_connect(url, autoclose=False, autoping=False) as ws:
await dispatch()


ARGS = argparse.ArgumentParser(
Expand All @@ -71,9 +70,8 @@ async def dispatch():

url = 'http://{}:{}'.format(args.host, args.port)

loop = asyncio.SelectorEventLoop(selectors.SelectSelector())
asyncio.set_event_loop(loop)
loop = asyncio.get_event_loop()

loop.add_signal_handler(signal.SIGINT, loop.stop)
asyncio.Task(start_client(loop, url))
loop.create_task(start_client(loop, url))
loop.run_forever()

0 comments on commit 57edaca

Please sign in to comment.