Skip to content

Instantly share code, notes, and snippets.

@mepholic
Created October 18, 2020 13:10
Show Gist options
  • Save mepholic/e188c4bf1b2550f936598747a271c778 to your computer and use it in GitHub Desktop.
Save mepholic/e188c4bf1b2550f936598747a271c778 to your computer and use it in GitHub Desktop.
Attempt at connecting to OpenMHz websocket
import socketio
import json
from signal import signal, SIGINT
sio = socketio.Client(logger=True, engineio_logger=True)
@sio.event
def connect():
print('connection established')
@sio.on('new message')
def my_message(data):
print('message received: {}'.format(data))
@sio.event
def disconnect():
print('disconnected from server')
def handler(signal_received, frame):
# Handle any cleanup here
print('SIGINT or CTRL-C detected. Exiting gracefully')
sio.emit('stop')
sio.disconnect()
if __name__ == '__main__':
# Tell Python to run the handler() function when SIGINT is recieved
signal(SIGINT, handler)
filterSet = {
"filterCode": "",
"filterType": "all",
"filterName": "OpenMHz",
"filterStarred": False,
"shortName": "chi_cpd"
}
startJson = json.dumps(filterSet)
print("Sending JSON: {}".format(filterSet))
sio.connect('https://api.openmhz.com/')
sio.emit('start', startJson)
sio.wait()
@mepholic
Copy link
Author

Output looks like this, no calls are ever received

Sending JSON: {'filterCode': '', 'filterType': 'all', 'filterName': 'OpenMHz', 'filterStarred': False, 'shortName': 'chi_cpd'}
Attempting polling connection to https://api.openmhz.com/socket.io/?transport=polling&EIO=3
Polling connection accepted with {'sid': 'xxxx', 'upgrades': ['websocket'], 'pingInterval': 25000, 'pingTimeout': 5000}
Engine.IO connection established
Received packet MESSAGE data 0
Namespace / is connected
connection established
Attempting WebSocket upgrade to wss://api.openmhz.com/socket.io/?transport=websocket&EIO=3
WebSocket upgrade was successful
Sending packet PING data None
Emitting event "start" [/]
Sending packet MESSAGE data 2["start","{\"filterCode\": \"\", \"filterType\": \"all\", \"filterName\": \"OpenMHz\", \"filterStarred\": false, \"shortName\": \"chi_cpd\"}"]
Received packet PONG data None
Sending packet PING data None
Received packet PONG data None
Sending packet PING data None
Received packet PONG data None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment