Skip to content

Instantly share code, notes, and snippets.

@Garmelon
Created March 29, 2017 16:37
Show Gist options
  • Save Garmelon/90ba9c247c48b62dde9b54f60cd3d573 to your computer and use it in GitHub Desktop.
Save Garmelon/90ba9c247c48b62dde9b54f60cd3d573 to your computer and use it in GitHub Desktop.
import ssl
import threading
import time
import websocket
from websocket import WebSocketException as WSException
SSLOPT = {"cert_reqs": ssl.CERT_NONE}
ws = None
def run():
print("Connecting")
global ws
ws = websocket.create_connection(
"wss://euphoria.io/room/test/ws",
enable_multithread=True,
sslopt=SSLOPT
)
print("Connected")
while True:
try:
ws.recv()
except (WSException, ConnectionResetError):
return
thread = threading.Thread(
target=run,
name="testthread"
)
thread.start()
while not ws:
time.sleep(1)
print("Closing connection in .5s:")
time.sleep(.5)
#ws.abort() # uncomment for working program, leave commented out for segfault >:D
ws.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment