Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
A Simple Implementation of Non-Blocking TCP Socket Server.
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
You can import the libary with the following statement:
import tcpnonblock
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()
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)
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()
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.
FAQs
A Simple Implementation of Non-Blocking TCP Socket Server.
We found that tcpnonblock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.