Skip to main content

Pyckage for creating high level multi-client server with E2E encryption.

Project description

A python package for creating multi-client server with high level of abstarction, meaning user don't need to write 100s of lines of code. User can write a multi-client server with just 12 lines fo code, it's that simple. In addition to this PySock also make the connections end-to-end encrypted. It also provide the functionality of creating a end-to-end encrypted connection between two or more client, meaning client can share the data with others client available.

In more simple terms PySock brings to versions of multi-client server. First one is just normal multi-client server with no encryption, user need to write there own wrapper kind fucntion to make it secure if they wants. Other version is highly secure. PySock implements E2E with the help of AES. The encryption is not just limited to client-server communication but it also encrypts cleint-client communication.

Below there are two examples listed, first is secure other is unsecure:


Sample Secure Server

Before creating secure version of server make sure you have a .yaml file as it is required

server.py

from PySock import Sserver

def client_msg(data):
    print(f"Message From : {data['sender_name']} => {data['data']}")

s = Sserver(
    file = r'server_yml.yaml',
    debug = False
    )
s.SERVER("localhost",1234,10)
s.CREATE_CHANNEL("test")

new_client = []

while True:
    for d in s.varifiedDevices:
        if d in s.conClients:       
            if d not in new_client:
                s.SEND(d,"test","Hello From Server")
                new_client.append(d)
        else:
            if d in new_client:
                new_client.remove(d)

    s.LISTEN("test",client_msg)

Sample Secure Clients

Before creating server make sure you have a .yaml file as it is required

clientOne.py

from PySock import Sclient

name = "shikhar"

def abc(data,con):
    print(f"Message from : {data['sender_name']} => {data['data']}")
    con.SEND("test","Hello!")

def client_msg(data):
    print(f"Message from : {data['sender_name']} => {data['data']}")

c = Sclient(client_name = name, file = r'clientOne_yml.yaml', debug = False)
c.CLIENT("localhost",1234)
c.CREATE_CHANNEL("test")

c.HANDSHAKE(target_name = "swat")
count = 0
while True:
    c.LISTEN( channel = "test", function = abc, args = (c,) )
    c.LISTEN( channel = "DSP_MSG", function = client_msg)

    if count == 0:
        if c.check("swat") in c.HS_Devices:
            c.SEND_TO_CLIENT(target_name = "swat", data = "Hello, what are you doing.")
            count += 1

clientTwo.py

from PySock import Sclient

name = "swat"

def abc(data,con):
    print(f"Message from : {data['sender_name']} => {data['data']}")
    con.SEND("test","What are you doing!")

def client_msg(data,con):
    print(f"Message From : {data['sender_name']} => {data['data']}")
    con.SEND_TO_CLIENT(target_name = data["sender_name"], data = f"Hello From {name}")

c = Sclient(client_name = name, file = r'clientTwo_yml.yaml', debug = False)
c.CLIENT("localhost",1234)
c.CREATE_CHANNEL("test")

count = 0
while True:
    c.LISTEN( channel = "test", function = abc, args = (c,) )
    c.LISTEN( channel = "DSP_MSG", function = client_msg, args = (c,))

    if count == 0:
        if "swat" in c.HS_Devices:
            c.SEND_TO_CLIENT(target_name = "swat", data = "Hello, what are you doing.")
            count += 1

===You can add as many client like these===

Result after running server.py, clientOne.py and clientTwo.py

Markdown logo



Now its time for normal multi-client server and clients:

Sample Server

server.py

from PySock import server

def client_msg(data):
    print(f"Message From : {data['sender_name']} => {data['data']}")

s = server(secure = False,debug = True)
s.SERVER("localhost",8888,10)
s.CREATE_CHANNEL("test")

new_client = []

while True:
    for d in s.conClients:
        if d not in new_client:
            s.SEND(d,"test","Hello From Server")
            new_client.append(d)

    s.LISTEN("test",client_msg)

Sample Clients

clientOne.py

from PySock import client

name = "shikhar"

def abc(data,con):
    print(f"Message from {data['sender_name']} : {data['data']}")
    con.SEND("test","Hello!")

c = client(client_name = name, debug = True)
c.CLIENT("localhost",8888)
c.CREATE_CHANNEL("test")

count = 0
while True:
    c.LISTEN( channel = "test", function = abc, args = (c,) )

    if count == 0:
        c.SEND_TO_CLIENT(target_name = "swat", data = "Hello, what are you doing.")
        count += 1

clientTwo.py

from PySock import client

def abc(data,con):
    print(f"Message from {data['sender_name']} : {data['data']}")
    con.SEND("test","Hurrah! it's working.")

def client_msg(data):
    print(f"Message from : {data['sender_name']} => {data['data']}")

c = client(client_name = "swat", debug = True)
c.CLIENT("localhost",8888)
c.CREATE_CHANNEL("test")
while True:
    c.LISTEN( channel = "test", function = abc, args = (c,) )

    c.LISTEN( channel = "DSP_MSG", function = client_msg)

There is no docs for this library but i'm working on docs, hope it will uploaded soon.

Thanks for visiting


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

PySock-0.0.3.1.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PySock-0.0.3.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file PySock-0.0.3.1.tar.gz.

File metadata

  • Download URL: PySock-0.0.3.1.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.4

File hashes

Hashes for PySock-0.0.3.1.tar.gz
Algorithm Hash digest
SHA256 8bbc921e503211ce820de686529f7b990bd03da8cf8b8e9f6188f0030638de9c
MD5 ad57663adcf8061bc5c090fc27921fac
BLAKE2b-256 4a3ade5a2710e92ce010f84acc8aed13826ffea985570f599b0431c5da4b144e

See more details on using hashes here.

File details

Details for the file PySock-0.0.3.1-py3-none-any.whl.

File metadata

  • Download URL: PySock-0.0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.4

File hashes

Hashes for PySock-0.0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c523bd7fd149472ca8a02ac125a1bc0d8b0b28219e12bfb3e2fecb09c228f603
MD5 2766c0b4e4ce4dd87eb603aeff1ea9ed
BLAKE2b-256 7d9433ae5d368da218c5876b19a3fcd85dda980b49dec253b74de2bd2b26873d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page