Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #114 from ergenerdem/master
Browse files Browse the repository at this point in the history
Added client-id and role fetching functionality for permission manager
  • Loading branch information
daschubert authored Dec 5, 2019
2 parents f100d33 + 30b53a6 commit 4bebdd5
Show file tree
Hide file tree
Showing 50 changed files with 24,493 additions and 195 deletions.
52 changes: 52 additions & 0 deletions direct-access-api/client-app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from autobahn.asyncio.websocket import WebSocketClientProtocol, \
WebSocketClientFactory

import json
import random

try:
import asyncio
except ImportError:
import trollius as asyncio


class MyClientProtocol(WebSocketClientProtocol):

def onConnect(self, response):
print("Server connected: {0}".format(response.peer))

async def onOpen(self):
print("WebSocket connection open.")

resp = json.loads('{"appid" : "", "secret" : ""}')
resp["action"] = "create"
# resp["vchannel"] = "vcan83"
resp["channel"] = "CAN0"
resp["appid"] = "ks-app1"
resp["secret"] = "d6d6846a-646a-4d70-ae86-91d3a4eeea79"

dictionaryToJson = json.dumps(resp)
self.sendMessage(dictionaryToJson.encode('utf8'))
await asyncio.sleep(1)

def onMessage(self, payload, isBinary):
if isBinary:
print("Binary message received: {0} bytes".format(len(payload)))
else:
# print("Text message received: {0}".format(payload.decode('utf8')))
resp = json.loads(payload.decode('utf8'))
print(resp)

def onClose(self, wasClean, code, reason):
print("WebSocket connection closed: {0}".format(reason))


if __name__ == '__main__':
factory = WebSocketClientFactory(u"ws://127.0.0.1:9000/vss")
factory.protocol = MyClientProtocol

loop = asyncio.get_event_loop()
coro = loop.create_connection(factory, '127.0.0.1', 9000)
loop.run_until_complete(coro)
loop.run_forever()
loop.close()
Loading

0 comments on commit 4bebdd5

Please sign in to comment.