Skip to main content

pSock

pSock is a socket / web module that helps developers and students to approach Server-Client creation and much more.

Developed by Andrea Vaccaro from ANDRVV (c) 2022

Installing

Linux, MacOS = pip3 install pSock --user

Windows = pip install pSock --user

How To Create a Server

import pSock; from threading import Thread



def ToRunOnlyInConnection(conn):

    print("This is a server!")

    print(f"Active connections {sock.getactiveconnections}")

    while True:

        received = sock.take(conn, codify = "utf-8", buffer = 2048)

        if received == "!quit":

            break

        print(received)

    sock.quit()





ip, port = "localhost", 80



sock = pSock.Net(pSock.AF_INET, pSock.SOCK_STREAM)

sock.createserver([ip, port])

sock.listen(ToListen = 1)

while True:

    conn, addr = sock.accept()

    Thread(ToRunOnlyInConnection, [conn]).start()

How To Create a Client

import pSock



ip, port = "localhost", 80



sock = pSock.Net(pSock.AF_INET, pSock.SOCK_STREAM)

sock.connect([ip, port])



print("This is a client!")

while True:

    tosend = input("> ")

    if tosend = "!quit":

        break

    sock.send(tosend, codify = "utf-8")

sock.quit()

Web Scraping

import pSock



pSock.Web.getresponsetext() 



json_data = pSock.Web.getresponsedata()

name = json_data[name]



to_research = pSock.Web.responsesearch("www.python.org", to_find)

Other Commands And Methods

Receive info, local and remote

import pSock



ip, port = "localhost", 80



sock = pSock.Net(pSock.AF_INET, pSock.SOCK_STREAM)

sock.createserver([ip, port])



protocol_name = "udp"



host = sock.gethost

address = sock.getaddr

active_connections = sock.getactiveconnections # Output: int

active_connection_data = sock.getactiveconnectionsdata # Output: list/tuple



my_host_name = pSock.gethostname()

fully_domain_name = pSock.getfdname()

get_proto = pSock.getproto(protocol_name)

get_service = pSock.getservice(port) # Insert name or port

get_host_remote = pSock.gethost(ip) # Insert IP or name



get_all_address_dict = pSock.getipconfig() 

# RETURN: MAC Address, IP, location of Address, Ethernet, Ethernet 2, LAN, LAN* 1, LAN* 2, Wi-Fi, Pseudo Interface

my_ipv4_address = get_all_address_dict["Address"][0] # Example



get_all_address_map = pSock.getipconfigmap()

# PRINT: MAC Address, IP, location of Address, Ethernet, Ethernet 2, LAN, LAN* 1, LAN* 2, Wi-Fi, Pseudo Interface

Sending without connections

import pSock



ip, port = "localhost", 80



sock = pSock.Net(pSock.AF_INET, pSock.SOCK_STREAM)



tosend = input("> ")



sock.sendto(tosend, codify = "utf-8", [ip, port])

Setting a temporary addr

import pSock



ip, port = "localhost", 80



sock = pSock.Net(pSock.AF_INET, pSock.SOCK_STREAM)



tosend = input("> ")



sock.setaddr(["localhost", 80])

sock.sendto(tosend, codify = "utf-8")



tosend = input("> ")



sock.setaddr(["localhost", 334])

sock.sendto(tosend, codify = "utf-8")



sock.setaddr(["localhost", 334])

sock.createserver()



sock.cancelsets() # To delete the IP and ports set

Metadata

Release files for pSock 1.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pSock 1.3.6
File Size Uploaded
pSock-1.3.6.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pSock 1.3.6
File Interpreter ABI Platform
pSock-1.3.6-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / pSock-1.3.6.tar.gz

Download URL pSock-1.3.6.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
020ddaf7a19ace0a2b86763f2f7f593e8dd60570ddb04f50544aebb79f5e92a6
BLAKE2b-256 checksum
How to use checksums
95f0e6844e323b3d15c456a3079e33ac8b6e7c7f9d1f1175756c7ebb2727fb26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release files / pSock-1.3.6-py3-none-any.whl

Download URL pSock-1.3.6-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca25244964541b005fe8a2db7e7ccf752e047a68d6d5ff3e3383bdc73a2aa11c
BLAKE2b-256 checksum
How to use checksums
e41421b861033fb6ffccca9abfc78304c85c7ca65894aa8d1de128e884aee636
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page