-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientSide.py
More file actions
32 lines (29 loc) · 975 Bytes
/
ClientSide.py
File metadata and controls
32 lines (29 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import websockets
import asyncio
import json
async def listen():
# 2222 is the port that the client will listen on
url = 'ws://localhost:2222'
# Behavior for connecting w Websocket
async with websockets.connect(url) as ws:
# Sends 'start' str to server
await ws.send('start')
while True:
# Waits for response from Server
startMsg = await ws.recv()
print(startMsg)
# Sends startN and endN to Server
print('Welcome to the Fibonacci Sequence Generator!')
startN = input('Starting index? ')
await ws.send(startN)
endN = input('How many rows? ')
await ws.send(endN)
# Waits for result from Server, decodes it and prints each number.
data = await ws.recv()
fiboArray = json.loads(data.decode())
for x in fiboArray:
print(x)
# Sends 'start' to trigger the above await
await ws.send('start')
# Runs listen()
asyncio.get_event_loop().run_until_complete(listen())