Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A Simple Implementation of Non-Blocking TCP Socket Server.

Project description

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)


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+

Note for Noobies: If python3 work then use python


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
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
def start(host, port):
    print("Server Start")

# On Server Stop Event
def stop():
    print("Server Stop")

# Start the Server
server.listen("", 8080) # Host,Port

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
def on_open():
    print("Connected to Server")
    client.send("Hello World!")

# On Client Disconnected from Server
def on_close():
    print("Disconnected to Server")

# On Server Message Received
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()

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.

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tcpnonblock, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size tcpnonblock-0.1.1-py3-none-any.whl (17.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size tcpnonblock-0.1.1.tar.gz (4.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page