https://github.com/wkhallen/dtppy
Cross-platform networking interfaces for Python.
https://github.com/wkhallen/dtppy
networking python socket socket-client socket-server
Last synced: 9 months ago
JSON representation
Cross-platform networking interfaces for Python.
- Host: GitHub
- URL: https://github.com/wkhallen/dtppy
- Owner: WKHAllen
- License: mit
- Created: 2022-08-20T19:53:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-06T04:14:31.000Z (10 months ago)
- Last Synced: 2025-03-06T05:23:26.039Z (10 months ago)
- Topics: networking, python, socket, socket-client, socket-server
- Language: Python
- Homepage: https://wkhallen.com/dtp
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Data Transfer Protocol for Python
Cross-platform networking interfaces for Python.
## Data Transfer Protocol
The Data Transfer Protocol (DTP) is a larger project to make ergonomic network programming available in any language.
See the full project [here](https://wkhallen.com/dtp/).
## Installation
Install the package:
```sh
$ python -m pip install dtppy
```
## Creating a server
A server can be built using the `Server` implementation:
```python
from dtppy import Server
# Called when data is received from a client
def receive(client_id, data):
# Send back the length of the string
s.send(len(data), client_id)
# Called when a client connects
def connect(client_id):
print(f"Client with ID {client_id} connected")
# Called when a client disconnects
def disconnect(client_id):
print(f"Client with ID {client_id} disconnected")
# Create a server that receives strings and returns the length of each string
s = Server(on_receive=receive, on_connect=connect, on_disconnect=disconnect)
s.start("127.0.0.1", 29275)
```
## Creating a client
A client can be built using the `Client` implementation:
```python
from dtppy import Client
message = "Hello, server!"
# Called when data is received from the server
def receive(data):
# Validate the response
print(f"Received response from server: {data}")
assert data == len(message)
# Called when the client is disconnected from the server
def disconnected():
print("Unexpectedly disconnected from server")
# Create a client that sends a message to the server and receives the length of the message
c = Client(on_receive=receive, on_disconnected=disconnected)
c.connect("127.0.0.1", 29275)
# Send the message to the server
c.send(message)
```
## Security
Information security comes included. Every message sent over a network interface is encrypted with AES-256. Key
exchanges are performed using a 512-bit RSA key-pair.