secure reliable udp socket implemented by PurePython
Project description
Secure Reliable UDP
This repository provides Secure Reliable Data Stream that works like TCP.
My purpose is enable users create P2P connection between clients in closed NAT.
Features
- Pure Python
- Usage like normal socket object
- Protocol similar to RUDP
- UDP hole punching
- high performance (4Mbps/s Up&Down when 10mb)
- ipv4/ipv6
Requirement
- Python3.6+
- requirements.txt
Installation
tutorial for users "cannot work on my condition"
pip3 install --user srudp
Demo
Prepare two independent PCs.
from srudp import SecureReliableSocket
from time import sleep, time
sock = SecureReliableSocket()
sock.connect(("<remote host 1>", 12345))
while not sock.is_closed:
sock.sendall(b'hello ' + str(time()).encode())
sleep(3)
print("closed", sock)
A side, send message hello once in a 3 sec.
from srudp import SecureReliableSocket
from time import time
sock = SecureReliableSocket()
sock.connect(("<remote host 2>", 12345))
while not sock.is_closed:
data = sock.recv(1024)
if not data:
break
print(time(), data)
print("closed", sock)
Another side, receive the message and show immediately.
to avoid troubles
- Do not think always success connection establish. Web-RTC detect UDP-hole-punching success, or use alternative way when failed, you need to implement it.
- UDP (and some TCP) is often blocked on public network like airport free wifi and university local LAN etc. Addition to it, some router and network adapter sometimes block.
- I designed this simple TCP like socket object. This don't have signaling function, haven't data specialized because I will use this as one of low-layer libraries for P2P.
Note: Why make this?
These days, PC is located in a local environment protected by NAT. It is difficult to transfer data between two outsides. In order to solve this problem, connection is realized by UDP hole punching without using UPnP.
UDP is a socket protocol with minimum functions for connecting applications. Therefore, there is no connection state, data may not be reachable, spoofing the source is easy. This is why, you cannot substitute it as TCP.
With this program, you can treat it just like TCP without worrying about the above problems. In other words, it has a connection state, guarantees data reachability, and is difficult to forge.
Links
- Winny -Port0 setting-
- lean about WebRTC
- (24days) NAT Traversal
- Peer-to-Peer Communication Across Network Address Translators
Author
Licence
MIT
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
File details
Details for the file srudp-0.3.3.tar.gz
.
File metadata
- Download URL: srudp-0.3.3.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bea70ac4048f089909a10825c028d5a0d792ebd19b3a0bbce01212c7a50151e3 |
|
MD5 | 169c3cdefe1de4fb5c482cc24c283a58 |
|
BLAKE2b-256 | c05a4936774016cf8184898b66a1909c7c586d5c2d827c289a2e9ce6376f220b |