Skip to main content

create multi-client server using multi-threading

Project description

Overview

serversock is a python module to create a server that can accept connection from multiple clients at the same time using multithreading.

Installation

serversock is listed in pypi so the installation is very simple

# in your terminal/CMD run

pip install serversock

Usage

Creating server

# import package
from serversock.serversock import _server

# create class object
serverCTRL = _server(address, port, bufffsize)

The arguments of _server are defined below as

class _server:
    def __init__(self, address:str, port: int, buffsize:int = 1024):
        """_server initialization

        Args:
            address (str): Enter Address like '0.0.0.0'
            port (int): Enter port number, example: 8080
            buffsize (int, optional): message buffsize. Defaults to 1024.
        """
        ...
    ...

After class object creation, start server

# start server

serverCTRL._start(serverfilename, responses)

The arguments of _start are defined below as:

class _server:
    ...
    def _start(self, serverfilename:str, responses:int = 1):
        """start server

        Args:
            serverfilename (str): serverfilename to save server data
            responses (int, optional): Number of response expected from client. Defaults to 1.
        """
        ...
    ...

Creating clients

# import _client class from serversock

from serversock.serversock import _client

# create class object
clientCTRL = _client(serveraddress, serverport, serverbufflimit)

The arguments of _client are defined below as:

class _client:
    def __init__(self, serveraddress:str, serverport:int, serverbufflimit:int = 1024):
        """_client class initialization

        Args:
            serveraddress (str): server address like '0.0.0.0'
            serverport (int): server port like 8080
            serverbufflimit (int, optional): buffersize. Defaults to 1024.
        """
        ...
    ...

After that client can perform a bunch of tasks like send a message, sync with the server and disconnect voluntarily.

  • send message and get response in return

    • client can send message to the server that the server will save.
    # send message
    clientCTRL._sendToServer(message)
    
  • sync with the server

    • the server sends the complete data that the server has stored to the client in the form of a string.
    # sync with the server
    completedata = clientCTRL._refresh() # this will return a string.
    
    # to get the list of lines in the file, do completedata.split('\n')
    completedata = completedata.split('\n')
    
  • disconnect voluntarily

    # disconnect
    clientCTRL._disconnect()
    

Terminal Controls

Check version

# in terminal/CMD, run

serversock -v # or serversock --version

Show help text

# in terminal/CMD run

serversock -h # or serversock --help

Uninstallation

serversock can be uninstalled using pip

# uninstall

pip uninstall serversock

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

serversock-0.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

serversock-0.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file serversock-0.1.tar.gz.

File metadata

  • Download URL: serversock-0.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for serversock-0.1.tar.gz
Algorithm Hash digest
SHA256 66148fbe23f3851afe7c8137d17f1d88702167bc39e47cd9305b537b12c96241
MD5 63c4cf93b55781f743ce7f4c123ead7f
BLAKE2b-256 074e9d22093440fdf720dec48b8452ae6ef799d9e06934241eac811d59ac77a6

See more details on using hashes here.

File details

Details for the file serversock-0.1-py3-none-any.whl.

File metadata

  • Download URL: serversock-0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for serversock-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d442ba03ef0a65799616e1f7e3d9a0fb04a96c763ab429fcdabf921f5283762d
MD5 0477488a87735437c2df4a7b33e3dc7c
BLAKE2b-256 9a63e93b9693ed388b2cbe78d88ee4ef209132dc97ceee0c08aa0ffefd2a09af

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