TCP Non-Block
A Simple Implementation of Non-Blocking TCP Socket Server.
Key Features
- Simple to Use
- Threading Built In
- Expandable - Does'nt use a thread per connection
- Stress Tested - Can handle 100+ connections (tested on a OVH VPS SSD 1)
Installation
You can install via python's pip module:
Install with Offical Python Package Index:
python3 -m pip install tcpnonblock
or with this Git Respiratory
python3 -m pip install git+https://github.com/SamHDev/tcpnonblock.git
Note for Noobies: If python3 work then use python
Usage
You can import the libary with the following statement:
import tcpnonblock
Server Example
Here is a quick Example of a TCPSocket Server. This is an Echo Server that replies the message from a client.
server = tcpnonblock.TCPSocketServer() # Create a Server Object
# Create a Client Instance for the Server
@server.client_instance
class ClientInstance(tcpnonblock.TCPSocketServerInstance):
# On Client Connect
def connect(self):
print("Client Connected")
# On Client Disconnect
def disconnect(self):
print("Client Disconnected")
# On Client Message
def message(self, msg):
print("Client Message: ",msg)
self.send("You Said: ", msg) # Echo the Message (Send)
# On Server Start Event
@server.on_start
def start(host, port):
print("Server Start")
# On Server Stop Event
@server.on_stop
def stop():
print("Server Stop")
# Start the Server
server.listen("0.0.0.0", 8080) # Host,Port
server.start()
Client Example
Here is a quick Example of a TCPSocket Client to go with our Echo Server. This is an Echo Client that interacts with our Example.
client = remote.TCPSocketClient() # Create a Client Object
# On Client Connected to Server
@client.on_open
def on_open():
print("Connected to Server")
client.send("Hello World!")
# On Client Disconnected from Server
@client.on_close
def on_close():
print("Disconnected to Server")
# On Server Message Received
@client.on_message
def on_message(msg):
print("Reply: ", msg) #`Msg` is a `string`
client.connect("localhost", 8080)
Threading
What about that threading I mentioned earlier, well its this simple.
Just declare the threading argument in the creation of the object.
It works for both TCPSocketServer and TCPSocketClient
server = tcpnonblock.TCPSocketServer(threaded=True)
client = rtcpnonblock.TCPSocketClient(threaded=True)
The Thread will be created and started on .start()
License and Attributes
Created by Sam Huddart under alias SamHDev for the Blume Open Source Project. SamHDev/tcpnonblock is licensed under the GNU General Public License v3.0 and is Open-Source as seen in LICENSE. Commercial use, Modification and Distribution are permmited. Although credit is not necessary, it is much obliged. If you do wish to credit the author, please link the respiratory and the author at github or website. Thank you for using our work.
Metadata
Release files for tcpnonblock 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tcpnonblock-0.1.1.tar.gz | 4.2 kB | Without provenance | Details for tcpnonblock-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tcpnonblock-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for tcpnonblock-0.1.1-py3-none-any.whl |
Total release size: 21.7 kB
Release files / tcpnonblock-0.1.1.tar.gz
| Download URL | tcpnonblock-0.1.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c44e7e0cf8986f8b9961ede9b891863a70d6c9468d4c2e3d4b96f59fe6e16b39
|
|
BLAKE2b-256 checksum How to use checksums |
55f5f1f15a1e020be64642ba620769bfd42f68c627d84e9feab3ef1516b7f029
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
|
Release files / tcpnonblock-0.1.1-py3-none-any.whl
| Download URL | tcpnonblock-0.1.1-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e15744966a6878066ce9b4ad9fddbb0a15d641fc82afaf716a5e94dfdd61ffb
|
|
BLAKE2b-256 checksum How to use checksums |
8a2830a59e108e2c75dd9be03dc675dfb2490dc4ee89b9543fa7940a04740da9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
|
Security for tcpnonblock 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.