A package for client-server communication over TCP and UDP
Project description
Network Package
This package provides a client-server communication system using TCP and UDP.
Installation
To install the package, run:
pip install network_com
Usage
Running the Server
To start the server, you can start the server using the package in your own script:
# my_script.py
from network-com import server
import threading
def start_server():
udp_thread = threading.Thread(target=server.send_ip)
tcp_thread = threading.Thread(target=server.tcp_server)
udp_thread.start()
tcp_thread.start()
udp_thread.join()
tcp_thread.join()
if __name__ == "__main__":
start_server()
Run the script with:
python my_script.py
Running the Client
To start the client, you can start the client using the package in your own script:
# my_script.py
from network_com import client
def start_client():
client.udp_listener()
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():
client.udp_listener()
def start_server():
udp_thread = threading.Thread(target=server.send_ip)
tcp_thread = threading.Thread(target=server.tcp_server)
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")
args = parser.parse_args()
if args.mode == 'client':
start_client()
elif args.mode == 'server':
start_server()
Run the script with:
# To start the server
python combined_script.py server
# To start the client
python combined_script.py client
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)
server_thread.start()
# Start client in the main thread (or another separate thread if desired)
start_client()
def start_server():
udp_thread = threading.Thread(target=server.send_ip)
tcp_thread = threading.Thread(target=server.tcp_server)
udp_thread.start()
tcp_thread.start()
udp_thread.join()
tcp_thread.join()
def start_client():
client.udp_listener()
if __name__ == "__main__":
main()
Run the script with:
python another_script.py
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
File details
Details for the file network_com-1.2.5.tar.gz
.
File metadata
- Download URL: network_com-1.2.5.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40555db468c4477937b3a2437f618b12938c4ea8edb994c7680f3c3a0ef3e589 |
|
MD5 | f88d94170324e0864f27c7d253eecdd3 |
|
BLAKE2b-256 | 9dd47a68eb2d924ea2fcae153c9de0cb08a9b1a80c662b10a4136a27ad443520 |
File details
Details for the file network_com-1.2.5-py3-none-any.whl
.
File metadata
- Download URL: network_com-1.2.5-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78f599f2873f3fc3c47f7d6271c6bdad5c9e6a941d60a154a923a1bcf2caca74 |
|
MD5 | 58fe57dc5ae7281d64a4d3b595c9dc74 |
|
BLAKE2b-256 | f9599410c3f280810c0ef5071fad275a6b1524add77dcd3eccbd52b9a7e39bdb |