Skip to main content

Swift Low-latency Intercommunication

Project description

SLIC - (Swift Low-latency Intercommunication)

SLIC (Swift Low-latency Intercommunication) simplifies client-server communication using tcp / p2p protocols while focusing on latency reduction through low-latency intercommunication techniques. By optimizing network protocols, minimizing data processing overhead, with optimized algorithms for data serialization and deserialization, reducing processing overhead and improving efficiency, while offering built-in capabilities like rate limiting and network traffic management for enhanced network efficiency and seamless data exchange to ensure faster response times, reduced communication delays, and enhanced overall performance in latency-sensitive applications.

Table of Contents

Introduction

SLIC is designed to simplify client-server communication in Python applications. It enables the creation of resources and handles incoming client requests, allowing for efficient data transfer between the client and server. The library incorporates features such as rate limiting to prevent abuse and network traffic management for tracking and monitoring client connections.

Quick Start

To quickly get started with SLIC, follow these steps:

  1. Install SLIC library:
$ pip install slicpy
  1. Import the necessary modules and classes:
from slic import Slic, RateLimiter, Rate, NetworkTrafficMap
  1. Create a server instance and define your resources:
server = Slic()

def my_resource(payload):
    # Handle the client request and return a response
    return {'message': 'Hello, World!'}

server.create_resource(':my_resource', my_resource)

# Add more resources as needed
  1. Start the server and listen for incoming connections:
server.start('localhost', 9999)
  1. Create a client instance and connect to the server:
client = Slic()
client.link('localhost', 9999)
  1. Send a request to the server and receive the response:
response = client.get_resource(':my_resource', {})
print(response['message'])

For more detailed information on the SLIC library and its usage, refer to the Usage section.

Features

SLIC provides the following key features:

  • Resource Creation: Create and manage resources on the server for handling specific client requests.
  • Request Handling: Handle incoming client requests and execute the associated resource logic.
  • Upload Resources: Enable clients to upload files or data to the server.
  • Rate Limiting: Apply rate limits to control the number of requests from a client within a given time frame. Network Traffic Management: Track and manage client connections and their request counts.

Usage

The SLIC library can be used to build client-server applications with ease. Below is a more detailed explanation of the library's usage and its main components.

Resource Creation

To create a resource on the server, use the create_resource method. This method takes two parameters: the access path and the resource function.

Example:

server.create_resource(':my_resource', my_resource_function)

Request Handling

SLIC handles incoming client requests through the handle_conns method. This method is executed in a separate thread for each client connection.

Example:

def handle_conns(conn, addr):
    # Handle the client connection and request here
    pass

    # Inside the Slic class
    thread = threading.Thread(target=handle_conns, args=(conn, addr))
    thread.start()

Upload Resources

SLIC allows clients to upload files or data to the server by creating upload resources using the create_upload_resource method. This method takes two parameters: the access path and the storage location.

server.py

from slic import Slic

# Create a SLIC server instance
server = Slic()

# Define an upload resource for handling file uploads
def handle_upload(payload):
    file_content = payload['file'].read()
    # Process the uploaded file content
    return {'success': True}

# Create an upload resource and assign it a unique access key
server.create_upload_resource(':upload', '/path/to/storage')

# Start the server on a specific host and port
server.start('localhost', 9999)

client.py

from slic import Slic

# Create a SLIC client instance
client = Slic()

# Connect to the SLIC server
client.connect('localhost', 9999)

# Upload a file to the server
with open('path/to/file.txt', 'rb') as file:
    response = client.upload_resource(':upload', 'path/to/file.txt')

print(response)  # {'success': True}

# Close the client connection
client.close()

Example Server

server.py

from slic import Slic

# Create a SLIC server instance
server = Slic()

# Define your resources (functions to handle client requests)
def add(payload):
    return {'answer': payload['a'] + 1}

def login(payload):
    return {'login': True}

# Create resources and assign them unique access keys
server.create_resource(':add', add)
server.create_resource(':login', login)

# Start the server on a specific host and port
server.start('localhost', 9999)

Example Client

To make requests to the SLIC server, you can use the SLIC client:

from slic import Slic

# Create a SLIC client instance
client = Slic()

# Connect to the SLIC server
client.connect('localhost', 9999)

# Send a request to the server
response = client.get_resource(':add', {'a': 10})
print(response)  # {'answer': 11}

# Close the client connection
client.close()

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

slicpy-0.0.9.tar.gz (10.3 kB view details)

Uploaded Source

File details

Details for the file slicpy-0.0.9.tar.gz.

File metadata

  • Download URL: slicpy-0.0.9.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for slicpy-0.0.9.tar.gz
Algorithm Hash digest
SHA256 fdf6235a7c595850988e6317eddc4e2ba3914e6874f1938eee0f364d39108c94
MD5 cb8fd9301cf625ae5cbf328be38d85a3
BLAKE2b-256 adcfdddc232d642db3bde81802a290bb55d6d50b526962b79fdab34cf2fdb07b

See more details on using hashes here.

Supported by

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