LoginSignup
0
0

More than 3 years have passed since last update.

PythonでWebsocketの通知を受け取る

Posted at

PythonでWebSocket通知を確認したかったので、作成してみた。

環境

OS Python
macOS 10.15.6 Python 3.8.5

準備

websocket-clientをインストールする


% pip3 install websocket-client

スクリプト


#-*- coding:utf-8 -*-

from websocket import create_connection
import sys
import signal

ws = None
try:
    #コネクションを張る
    ws = create_connection("ws://192.168.0.1/v1/changes")
    #受信したメッセージを表示
    while True:
        recv = ws.recv()
        print(recv)

except:
    print("except")

finally:
    if ws is not None:
        ws.close()
    print("connection close")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0