Skip to main content

a simple python server and client to interconnect the hosts of your application

Project description

Pyintercon is a simple python server and client to interconnect the hosts of your application.

All package that use in this is built-in packages (refer in requirements.txt)

The server is activate on server host, and the client in all application clients (interconnected).

Client send request to Server and the Server answered. The traitement function of server can be edit by developper.

Example:

Server:

    >>> from pyintercon import Server

    >>> # initialize the server
    >>> sv = Server(nb_client = 1)

    >>> # run the server on $host address and $port
    >>> sv.actiavte("localhost", 8080)
    """Server is activated on localhost:8080...
    Tap CTRL + C to quit !!!!!"""

Client

    >>> from pyintercon import Client

    >>> # initialize the client
    >>> cl = Client()

    >>> """ server output:
        ('127.0.0.1', 44042) is connected ...
    """

    >>> # connect client to server on $host address and $port
    >>> cl.connect("localhost", 8080)

    >>> # Now send request to server and get response
    >>> response = cl.send({ message: "Hello World !" })

    >>> print(response)
    {'status': 1, 'message': 'default'}
    >>> # use disconnected method to disconnect server
    >>> cl.disconnect()

    >>> """ server output:
        ('127.0.0.1', 44042) is disconnected ...
    """

The server manage the response loader by the treatment function.

This function take the request data (dict object) and return by default {"status": 1, "message": "default"}.
He can edit it by set server.treatment = your_treatment_function

   >>> sv = Server() # One client by default
   >>> sv.treatment = your_treatment_function

Last's example:

Server

from pyintercon import Server

def response_loader(request):
    """ Just reverse the message content.
        He take dict object and return dict object

    """

    res = {"message": request["message"][::-1]}

    return res

def main():
    sv = Server()

    # set the treatment function
    sv.treatment = response_loader

    sv.activate("localhost", 8080)

if __name__ == "__main__":
    main()

Client

    >>> from pyintercon import Client
    >>> cl = Client()
    >>> cl.connect("localhost", 8080)
    >>> res = cl.send({"message": "Hello World !"})
    >>>
    >>> print(res)
    {"message": "! dlroW olleH"}

Futures:

  • Use threading for get client simultaneously with manage request response.
  • Add more events, possibility to emit events.

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

pyintercon-0.0.2.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

pyintercon-0.0.2-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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