Skip to main content

A WebSocket server that handles chunked data transfer with ACK/request flow.

Project description

@Install Python Dependencies-> >>> pip install -r Server_Sim

@Run the WebSocket Server -> Start the WebSocket server once per process. Asynchronous: >>> import asyncio >>> from Server_Sim import start_server >>> asyncio.run(start_server())

Synchronous:
Starts the server in a background thread.
>>> import threading
>>> from Server_Sim import start_server_sync
>>> threading.Thread(target=start_server_sync, daemon=True).start()
>>> # You might need to press enter again to continue

@Send Data to the Extension --> Asynchronous: >>> import asyncio >>> from Server_Sim import send >>> asyncio.run(send("Your data here"))

Synchronous:
>>> from Server_Sim import send_sync
>>> threading.Thread(target=lambda: send_sync("Your data here"), daemon=True).start()

@Receive Data from the Extension --> Reconstruct data from received chunks (if any). Waits until all expected chunks are received or timeout occurs. Asynchronous: >>> import asyncio >>> from Server_Sim import receive >>> result = asyncio.run(receive(expected_chunks=5, timeout=10)) >>> print(result)

Synchronous:
>>> from Server_Sim import receive_sync
>>> import queue
>>> result_queue = queue.Queue()
>>> thread = threading.Thread(target=lambda: result_queue.put(receive_sync(expected_chunks=5, timeout=10)), daemon=True)  # The number of chunks is the amount retun during send_sync() and timeout is how long it will wait
>>> thread.start()
>>> data = result_queue.get()
>>> print("Received data:", data)

@Load the Chrome Extension -> Open Chrome and navigate to chrome://extensions/ Enable Developer Mode (toggle in the top right) Click Load unpacked Select the extension/ directory/ Server_Sim [RECOMMENDED: Disable the extension when not using...]

@Use the Extension -> Click the extension icon in the Chrome toolbar Click “Connect to Localhost” after you Run the Websocket WebSocket connection will be established with the Python server

@Data Flow -> The Python server sends data chunks via WebSocket The extension stores chunks in localStorage and sends back acknowledgments (ack) You can reconstruct the received data using: reconstructData(totalChunks) inside the browser’s developer console.

@Important Notes -> You must run the server (start_server_sync) before calling send_sync() or receive_sync(). All operations happen within a single process, using threading to share memory. The Chrome extension must be open and connected to receive data. Chunk size is 5MB by default, even small strings are chunked (just 1 chunk).

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

server_sim-0.1.7.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

server_sim-0.1.7-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file server_sim-0.1.7.tar.gz.

File metadata

  • Download URL: server_sim-0.1.7.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.5

File hashes

Hashes for server_sim-0.1.7.tar.gz
Algorithm Hash digest
SHA256 8189c4b357f5af109f5ba2744e60258f089df016b44a3af362a5279f4f404443
MD5 b584a625e8a68dae8e2f852017cf815c
BLAKE2b-256 c5c703ccdad2d8baed99d47ebef074187519617a8bccb043dd2e6b3431d9a9c3

See more details on using hashes here.

File details

Details for the file server_sim-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: server_sim-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.5

File hashes

Hashes for server_sim-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fab94e1e713989f4ac95598237271c46edb8937cc6a9a85754c158af51dc1f0f
MD5 6e8c3808afbc56f0250a48bf58234532
BLAKE2b-256 a541f129f8b2492e6f44cb36f3597efac8769db9c9e25fbaa9abd28e8dbe08cb

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