Network Package
This package provides a client-server communication system using TCP and UDP With SSL/TLS security Certification.
Installation
To install the package, run:
pip install network_com
Generating SSL Certificates
To use SSL/TLS with this package, you need to generate SSL certificates. For development purposes, you can create self-signed certificates using OpenSSL:
Generate a Private Key
openssl genpkey -algorithm RSA -out server.key
Generate a Certificate Signing Request (CSR)
openssl req -new -key server.key -out server.csr -subj "/CN=example.com"
###Generate a Self-Signed Certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
You will have server.key and server.crt files to be used by the server.
Using OpenSSL
Install OpenSSL
If you don't already have OpenSSL installed, you can install it:
On Ubuntu:
sudo apt-get install openssl
On macOS (using Homebrew):
brew install openssl
On Windows:
Download and install from OpenSSL for Windows.
Usage
Running the Server
To start the server, you can start the server using the package in your own script:
# my_server_script.py
from network_com import server
import threading
import os
def start_server():
script_dir = os.path.dirname(os.path.abspath(__file__))
udp_thread = threading.Thread(target=server.send_ip)
tcp_thread = threading.Thread(target=server.tcp_server, args=(os.path.join(script_dir, 'server.crt'), os.path.join(script_dir, 'server.key')))
udp_thread.start()
tcp_thread.start()
udp_thread.join()
tcp_thread.join()
if __name__ == "__main__":
start_server()
Run the script with:
python my_server_script.py
Running the Client
To start the client, you can start the client using the package in your own script:
# my_client_script.py
from network_com import client
import os
def start_client():
script_dir = os.path.dirname(os.path.abspath(__file__))
client.udp_listener(os.path.join(script_dir, 'server.crt'))
if __name__ == "__main__":
start_client()
Run the script with:
python my_script.py
Combined Example
Here is an example script (combined_script.py) that allows you to run either the client or the server based on a command-line argument:
# combined_script.py
from network_com import client, server
import threading
import argparse
def start_client(certfile):
client.udp_listener(certfile)
def start_server(certfile, keyfile):
udp_thread = threading.Thread(target=server.send_ip)
tcp_thread = threading.Thread(target=server.tcp_server, args=(certfile, keyfile))
udp_thread.start()
tcp_thread.start()
udp_thread.join()
tcp_thread.join()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run network client or server.")
parser.add_argument('mode', choices=['client', 'server'], help="Mode to run: client or server")
parser.add_argument('--certfile', required=True, help="Path to the SSL certificate file")
parser.add_argument('--keyfile', help="Path to the SSL key file (required for server)")
args = parser.parse_args()
if args.mode == 'client':
start_client(args.certfile)
elif args.mode == 'server':
if not args.keyfile:
parser.error("The --keyfile argument is required for running the server")
start_server(args.certfile, args.keyfile)
Run the script with:
# To start the server
python combined_script.py server --certfile path/to/server.crt --keyfile path/to/server.key
# To start the client
python combined_script.py client --certfile path/to/server.crt
Using the Package in Other Projects
You can import and use the package in any other Python project. Here’s an example:
# another_script.py
from network_com import client, server
import threading
def main():
# Start server in a separate thread
server_thread = threading.Thread(target=start_server, args=(os.path.join(script_dir, 'server.crt'), os.path.join(script_dir, 'server.key')))
server_thread.start()
# Start client in the main thread (or another separate thread if desired)
start_client("path/to/server.crt")
def start_server(certfile, keyfile):
udp_thread = threading.Thread(target=server.send_ip)
tcp_thread = threading.Thread(target=server.tcp_server, args=(certfile, keyfile))
udp_thread.start()
tcp_thread.start()
udp_thread.join()
tcp_thread.join()
def start_client(certfile):
client.udp_listener(certfile)
if __name__ == "__main__":
main()
Run the script with:
python another_script.py
Metadata
Release files for network-com 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| network_com-1.3.0.tar.gz | 4.9 kB | Without provenance | Details for network_com-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| network_com-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for network_com-1.3.0-py3-none-any.whl |
Total release size: 11.2 kB
Release files / network_com-1.3.0.tar.gz
| Download URL | network_com-1.3.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
700adaed2f19bb6cc2da2e7d9ffbe5ca497df8b38406d3f36eac385f8f455df0
|
|
BLAKE2b-256 checksum How to use checksums |
d71cb40e5baa98e4646a40c0e2da3cd4be149a82491effd71c68390e79cd57fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / network_com-1.3.0-py3-none-any.whl
| Download URL | network_com-1.3.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a762a4dca4b3873b4f8cafbbe6d8e24981490d87098bb576a94156701141016
|
|
BLAKE2b-256 checksum How to use checksums |
d61391c63ec7df64731e3b50f77a39866965f8d49fbcfcc593389ef2954909e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Security for network-com 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.