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.3.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for pyintercon-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bd23078ff4f082ddc6224338d8861aa03ccd193d37a46977a327cff2d13cc40 |
|
MD5 | 9c5fcfa67b3c6c65232ebcbbba31c1ab |
|
BLAKE2b-256 | aa0b11dd53124973181cc48a9b089f57270d748a677daf69de8848a17bf62cf4 |