Giter VIP home page Giter VIP logo

serversock's Introduction

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

serversock's People

Contributors

d33pster avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.