pSock is a socket / threading module that helps developers and students to approach Server-Client creation and much more.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pSock-1.3.6.tar.gz.
File metadata
- Download URL: pSock-1.3.6.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
020ddaf7a19ace0a2b86763f2f7f593e8dd60570ddb04f50544aebb79f5e92a6
|
|
| MD5 |
252123a850a5977738b97d92ebf213e9
|
|
| BLAKE2b-256 |
95f0e6844e323b3d15c456a3079e33ac8b6e7c7f9d1f1175756c7ebb2727fb26
|
File details
Details for the file pSock-1.3.6-py3-none-any.whl.
File metadata
- Download URL: pSock-1.3.6-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca25244964541b005fe8a2db7e7ccf752e047a68d6d5ff3e3383bdc73a2aa11c
|
|
| MD5 |
b166b65c5a584bad7e1098295bdcf965
|
|
| BLAKE2b-256 |
e41421b861033fb6ffccca9abfc78304c85c7ca65894aa8d1de128e884aee636
|