A module implementing a peer-to-peer communication protocol over TCP/IP.
Project description
dpea-p2p
A module implementing a peer-to-peer communication protocol over TCP/IP.
A server begins listening on a particular port, and a client then connects to it via its IP.
The two can then send "packets" containing a packet type, specified by a shared enum, and a payload.
Example usage
On the server:
import enum
from dpea_p2p import Server
class PacketType(enum.Enum):
NULL = 0
COMMAND1 = 1
COMMAND2 = 2
# |Bind IP |Port |Packet enum
s = Server("172.17.21.2", 5001, PacketType)
s.open_server()
s.wait_for_connection()
assert s.recv_packet() == (PacketType.COMMAND1, b"Hello!")
s.send_packet(PacketType.COMMAND2, b"Hello back!")
s.close_connection()
s.close_server()
On the client:
import enum
from dpea_p2p import Client
class PacketType(enum.Enum):
NULL = 0
COMMAND1 = 1
COMMAND2 = 2
# |Server IP |Port |Packet enum
c = Client("172.17.21.2", 5001, PacketType)
c.connect()
c.send_packet(PacketType.COMMAND1, b"Hello!")
assert c.recv_packet() == (PacketType.COMMAND2, b"Hello back!")
c.close_connection()
Packet Structure
The packet structure looks like this:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Packet Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Payload +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 dpea_p2p-0.0.1.tar.gz.
File metadata
- Download URL: dpea_p2p-0.0.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7008428f88ae971ee80f084b61066240b102b8d9fea53ae9141013366c84022
|
|
| MD5 |
07f6491b55e7aabaf15e878579b11c55
|
|
| BLAKE2b-256 |
4a2b105ca64b170421db3d89c48e33cbf331f6fbb54bfd3350419615dbe4bd82
|
File details
Details for the file dpea_p2p-0.0.1-py3-none-any.whl.
File metadata
- Download URL: dpea_p2p-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b250daf44bc8e5f9020a6846ddf579bb22793605de0b151ab57570c04d62964e
|
|
| MD5 |
b5833017886e4847321850ccc7595bb7
|
|
| BLAKE2b-256 |
46678d319c20582b570c8a785787c439128a5e3d816a97b5b90337968484f9ef
|