Package: slicpy
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 ContentsIntroductionQuick StartFeaturesUsageContributingLicenseIntroductionSLIC 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 StartTo quickly get started with SLIC, follow these steps:Install SLIC library:$pipinstallslicpyImport the necessary modules and classes:fromslicimportSlic,RateLimiter,Rate,NetworkTrafficMapCreate a server instance and define your resources:server=Slic()defmy_resource(payload):# Handle the client request and return a responsereturn{'message':'Hello, World!'}server.create_resource(':my_resource',my_resource)# Add more resources as neededStart the server and listen for incoming connections:server.start('localhost',9999)Create a client instance and connect to the server:client=Slic()client.link('localhost',9999)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.FeaturesSLIC 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.UsageThe 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 CreationTo 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 HandlingSLIC handles incoming client requests through the handle_conns method. This method is executed in a separate thread for each client connection.Example:defhandle_conns(conn,addr):# Handle the client connection and request herepass# Inside the Slic classthread=threading.Thread(target=handle_conns,args=(conn,addr))thread.start()Upload ResourcesSLIC 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.pyfromslicimportSlic# Create a SLIC server instanceserver=Slic()# Define an upload resource for handling file uploadsdefhandle_upload(payload):file_content=payload['file'].read()# Process the uploaded file contentreturn{'success':True}# Create an upload resource and assign it a unique access keyserver.create_upload_resource(':upload','/path/to/storage')# Start the server on a specific host and portserver.start('localhost',9999)client.pyfromslicimportSlic# Create a SLIC client instanceclient=Slic()# Connect to the SLIC serverclient.connect('localhost',9999)# Upload a file to the serverwithopen('path/to/file.txt','rb')asfile:response=client.upload_resource(':upload','path/to/file.txt')print(response)# {'success': True}# Close the client connectionclient.close()Example Serverserver.pyfromslicimportSlic# Create a SLIC server instanceserver=Slic()# Define your resources (functions to handle client requests)defadd(payload):return{'answer':payload['a']+1}deflogin(payload):return{'login':True}# Create resources and assign them unique access keysserver.create_resource(':add',add)server.create_resource(':login',login)# Start the server on a specific host and portserver.start('localhost',9999)Example ClientTo make requests to the SLIC server, you can use the SLIC client:fromslicimportSlic# Create a SLIC client instanceclient=Slic()# Connect to the SLIC serverclient.connect('localhost',9999)# Send a request to the serverresponse=client.get_resource(':add',{'a':10})print(response)# {'answer': 11}# Close the client connectionclient.close()