{"action":"opened","issue":{"url":"https://api.github.com/repos/websocket-client/websocket-client/issues/424","repository_url":"https://api.github.com/repos/websocket-client/websocket-client","labels_url":"https://api.github.com/repos/websocket-client/websocket-client/issues/424/labels{/name}","comments_url":"https://api.github.com/repos/websocket-client/websocket-client/issues/424/comments","events_url":"https://api.github.com/repos/websocket-client/websocket-client/issues/424/events","html_url":"https://github.com/websocket-client/websocket-client/issues/424","id":319042722,"number":424,"title":"Sending message through long lived connection","user":{"login":"jtfarks","id":18206107,"avatar_url":"https://avatars0.githubusercontent.com/u/18206107?v=4","gravatar_id":"","url":"https://api.github.com/users/jtfarks","html_url":"https://github.com/jtfarks","followers_url":"https://api.github.com/users/jtfarks/followers","following_url":"https://api.github.com/users/jtfarks/following{/other_user}","gists_url":"https://api.github.com/users/jtfarks/gists{/gist_id}","starred_url":"https://api.github.com/users/jtfarks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtfarks/subscriptions","organizations_url":"https://api.github.com/users/jtfarks/orgs","repos_url":"https://api.github.com/users/jtfarks/repos","events_url":"https://api.github.com/users/jtfarks/events{/privacy}","received_events_url":"https://api.github.com/users/jtfarks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-30T21:30:20Z","updated_at":"2018-04-30T21:30:20Z","closed_at":null,"author_association":"NONE","body":"I'm playing with the package and have it up and running fine for receiving the messages i receive back.\r\n\r\nI am stumped with how to send a message back at an irregular interval, as defined by a different function. So far I am sending my authentification messages during on_open. I run a function in a different thread that sends a message back through the websocket when a predefined condition is met.\r\n\r\nIf i put my ws.send() inside on_message it works fine, but only reacts every time a message is received. How can I send this message from outside the function so that I can send it as and when I wish? Here is the code I am working with at the moment:\r\n\r\n`import websocket\r\nimport json\r\nfrom threading import Thread\r\ntry:\r\n    import thread\r\nexcept ImportError:\r\n    import _thread as thread\r\nimport time\r\n\r\n\r\ndef on_message(ws, message):\r\n\r\n    print(message)\r\n\r\ndef on_error(ws, error):\r\n    print(error)\r\n    print(time.strftime('%H:%M:%S'))\r\n\r\ndef on_close(ws):\r\n\r\n    print(\"### closed ###\")\r\n    print(time.strftime('%H:%M:%S'))\r\n\r\n\r\ndef on_open(ws):\r\n\r\n    def run(*args):\r\n\r\n        ws.send(json.dumps({\r\n            <authentfication data>\r\n\r\n        }))\r\n\r\n\r\n    thread.start_new_thread(run, ())\r\n\r\n\r\n\r\nwebsocket.enableTrace(True)\r\nws = websocket.WebSocketApp('<ws address>',\r\n                          on_message = on_message,\r\n                          on_error = on_error,\r\n                          on_close = on_close)\r\nws.on_open = on_open\r\n\r\n\r\ndef a():\r\n    ws.run_forever()\r\n\r\ndef b():\r\n    time.sleep(5)\r\n    ws.send(json.dumps(<message>))\r\n\r\n\r\nthread1 = Thread(target=a)\r\nthread1.start()\r\nthread1.join()\r\n\r\nthread2 = Thread(target=b)\r\nthread2.start()\r\nthread2.join()\r\n` \r\n\r\nI would expect the ws.send(json.dumps(<message>)) in thread2 to send a message through the authenticated connection in thread1? \r\n\r\nI'm not so sure its a bug of any sort, rather than just my poor execution... Any pointers in the right direction would be very much appreciated.\r\n\r\n\r\n"}}
{"actor":{"display_login":"jtfarks"}}