liuyuqi-dellpc 5 years ago
parent
commit
f6a2aec8fa
6 changed files with 151 additions and 0 deletions
  1. 0 0
      requirement.txt
  2. 2 0
      requirements.txt
  3. 52 0
      test/kuaishou_socket.py
  4. 22 0
      test/que.py
  5. 38 0
      test/sssocket.py
  6. 37 0
      test/t2.py

+ 0 - 0
requirement.txt


+ 2 - 0
requirements.txt

@@ -0,0 +1,2 @@
+aiowebsocket==1.0.0.dev2
+asyncio

+ 52 - 0
test/kuaishou_socket.py

@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@File    :   kuaishou_socket.py
+@Time    :   2019/05/28 03:00:17
+@Author  :   Liuyuqi 
+@Version :   1.0
+@Contact :   liuyuqi.gov@msn.cn
+@License :   (C)Copyright 2019
+@Desc    :   None
+
+Request URL: wss://live-ws-pg-group2.kuaishou.com/websocket
+Request Method: GET
+Status Code: 101 Switching Protocols
+
+Accept-Encoding: gzip, deflate, br
+Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
+Cache-Control: no-cache
+Connection: Upgrade
+Host: live-ws-pg-group2.kuaishou.com
+Origin: https://live.kuaishou.com
+Pragma: no-cache
+Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
+Sec-WebSocket-Key: opUwBCN/VZdDkpQSokZJIQ==
+Sec-WebSocket-Version: 13
+Upgrade: websocket
+User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
+
+'''
+import asyncio
+import logging
+from datetime import datetime
+from aiowebsocket.converses import AioWebSocket
+
+# url = 'wss://api.bbxapp.vip/v1/ifcontract/realTime'
+url = 'wss://live-ws-pg-group2.kuaishou.com/websocket'
+
+async def startup(uri):
+    async with AioWebSocket(uri) as aws:
+        converse = aws.manipulator
+        # 客户端给服务端发送消息
+        await converse.send('{"action":"subscribe","args":["QuoteBin5m:14"]}')
+        while True:
+            mes = await converse.receive()
+            print('{time}-Client receive: {rec}'.format(
+                time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))
+
+if __name__ == '__main__':
+    try:
+        asyncio.get_event_loop().run_until_complete(startup(url))
+    except KeyboardInterrupt as exc:
+        logging.info('Quit.')

+ 22 - 0
test/que.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@File    :   que.py
+@Time    :   2019/05/28 02:51:02
+@Author  :   Liuyuqi 
+@Version :   1.0
+@Contact :   liuyuqi.gov@msn.cn
+@License :   (C)Copyright 2019
+@Desc    :   None
+'''
+
+try:
+    import queue
+except ImportError:
+    import Queue as queue
+
+try:
+    import asyncio
+    print("Ss")
+except Exception as e:
+    print(e)

+ 38 - 0
test/sssocket.py

@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@File    :   socket.py
+@Time    :   2019/05/28 02:14:15
+@Author  :   Liuyuqi 
+@Version :   1.0
+@Contact :   liuyuqi.gov@msn.cn
+@License :   (C)Copyright 2019
+@Desc    :   None
+
+pip install asyncio
+pip install aiowebsocket
+'''
+
+import asyncio
+import logging
+from datetime import datetime
+from aiowebsocket.converses import AioWebSocket
+
+
+async def startup(uri):
+    async with AioWebSocket(uri) as aws:
+        converse = aws.manipulator
+        # 客户端给服务端发送消息
+        await converse.send('{"action":"subscribe","args":["QuoteBin5m:14"]}')
+        while True:
+            mes = await converse.receive()
+            print('{time}-Client receive: {rec}'.format(
+                time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))
+
+
+if __name__ == '__main__':
+    url = 'wss://api.bbxapp.vip/v1/ifcontract/realTime'
+    try:
+        asyncio.get_event_loop().run_until_complete(startup(url))
+    except KeyboardInterrupt as exc:
+        logging.info('Quit.')

+ 37 - 0
test/t2.py

@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@File    :   t2.py
+@Time    :   2019/05/28 03:11:04
+@Author  :   Liuyuqi 
+@Version :   1.0
+@Contact :   liuyuqi.gov@msn.cn
+@License :   (C)Copyright 2019
+@Desc    :   None
+'''
+
+import asyncio
+import logging
+from datetime import datetime
+from aiowebsocket.converses import AioWebSocket
+
+
+async def startup(uri):
+    async with AioWebSocket(uri) as aws:
+        converse = aws.manipulator
+        message = b'AioWebSocket - Async WebSocket Client'
+        while True:
+            await converse.send(message)
+            print('{time}-Client send: {message}'.format(
+                time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
+                message=message))
+            mes = await converse.receive()
+            print('{time}-Client receive: {rec}'.format(
+                time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))
+
+if __name__ == '__main__':
+    remote = 'ws://echo.websocket.org'
+    try:
+        asyncio.get_event_loop().run_until_complete(startup(remote))
+    except KeyboardInterrupt as exc:
+        logging.info('Quit.')