Skip to main content

A Python library that lets you communicate through JavaScript WebSocket client

Project description

PyJSSocket

This is a Python library that lets you communicate through JavaScript WebSocket client.

Installation

To install this library run pip install pyjssocket in your terminal.

Example

Here is an example of a server that can handle multiple calls from a different JS clients

import json
import jsserver
import socketserver

import threading
import time

class MyJsRequestHandler(jsserver.JSBaseRequestHandler):

    def on_handshake(self, host: str, url: str, seqKey: str):
        def target():
            while True:
                self.send_response(json.dumps({'success': True, 'time': time.time()}))
                time.sleep(1)

        super().on_handshake(host, url, seqKey)

        thread = threading.Thread(target=target, daemon=True)
        thread.start()

    def on_message(self, data: bytes):
        self.send_response(json.dumps({'success': True, 'time': time.time()}))

    def on_error(self, value: str):
        self.send_response(json.dumps({'success': False, 'message': value}))

if __name__ == '__main__':
    with socketserver.ThreadingTCPServer(('0.0.0.0', 451), MyJsRequestHandler) as tcpServer:
        tcpServer.serve_forever()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyjssocket-1.0.4.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyjssocket-1.0.4-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pyjssocket-1.0.4.tar.gz.

File metadata

  • Download URL: pyjssocket-1.0.4.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for pyjssocket-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b96a39eee668d995be38839d2d8ae6e99cf3008b8930853bb75d0695eb1c2c97
MD5 2d04526795273540d2a3fca99d5baecc
BLAKE2b-256 f848ee16ad6638bb1589716610d3788f97a1e54266a9ffb1c922ee2d1d8eaf28

See more details on using hashes here.

File details

Details for the file pyjssocket-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyjssocket-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for pyjssocket-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fbb7104f666af63038cee1dac2a8b9357bbd04e90a0c5d439495886d2c95db55
MD5 3f078112194d4f95bff57f852ffe77c7
BLAKE2b-256 06fa06298fe7467f55e2b329a0de8df12c7a2a974a6ea9d40ba5fa8ca376d111

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page