Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

network_com-1.2.3.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

network_com-1.2.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file network_com-1.2.3.tar.gz.

File metadata

  • Download URL: network_com-1.2.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for network_com-1.2.3.tar.gz
Algorithm Hash digest
SHA256 ef5ba339c3872deee7c590f3e51f58f426c51850891d49aee6767f0e79631fdf
MD5 dd2a2e12667c69f653f389c9a72ba794
BLAKE2b-256 b379676377877f9fc2979ca5efe564dd41a4deff2c316466c07da9998403c05b

See more details on using hashes here.

File details

Details for the file network_com-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: network_com-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for network_com-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3eaa773cf73a8b9617f8dce3ec1d48c09d3621e9f67d8ed897905c2a2a24d194
MD5 b30d7347950e0daa5c6801f9642963e2
BLAKE2b-256 5f949dd7286824f0bcd82f0f8e45cece6c69a049054a466a6c18566f752436ec

See more details on using hashes here.

Supported by

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