All Projects → fschr → Simpletcp

fschr / Simpletcp

Licence: agpl-3.0
A minimal non-blocking TCP server written for Python 3.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Simpletcp

Simpleunitytcp
🖧 Simple Unity Project to show how TCP communication are builded in C# without multi-threading or Unity network (Unet) involved.
Stars: ✭ 22 (-86.42%)
Mutual labels:  tcp, tcp-server, tcp-client
EasyFileTransfer
An easy way to transfer file with any size on network with tcp protocol.
Stars: ✭ 30 (-81.48%)
Mutual labels:  tcp, tcp-server, tcp-client
ctsTraffic
ctsTraffic is a highly scalable client/server networking tool giving detailed performance and reliability analytics
Stars: ✭ 125 (-22.84%)
Mutual labels:  tcp, tcp-server, tcp-client
SuperSimpleTcp
Simple wrapper for TCP client and server in C# with SSL support
Stars: ✭ 263 (+62.35%)
Mutual labels:  tcp, tcp-server, tcp-client
Simpletcp
Simple wrapper for TCP client and server in C# with SSL support
Stars: ✭ 99 (-38.89%)
Mutual labels:  tcp, tcp-server, tcp-client
tcp-net
Build tcp applications in a stable and elegant way
Stars: ✭ 42 (-74.07%)
Mutual labels:  tcp, tcp-server, tcp-client
Tinytcpserver
A small tcp server working under Mono or .NET (4.0) and provides hooks for handling data exchange with clients (works under mono and .net). Behaviour/protocol/reaction could be specified via custom C# script.
Stars: ✭ 14 (-91.36%)
Mutual labels:  tcp, tcp-server, tcp-client
Oksocket
An blocking socket client for Android applications.
Stars: ✭ 2,359 (+1356.17%)
Mutual labels:  tcp, tcp-server, tcp-client
Packetsender
Network utility for sending / receiving TCP, UDP, SSL
Stars: ✭ 1,349 (+732.72%)
Mutual labels:  tcp, tcp-server, tcp-client
Tacopie
C++ TCP Library - NO LONGER MAINTAINED
Stars: ✭ 359 (+121.6%)
Mutual labels:  tcp, tcp-server, tcp-client
AsyncTcpClient
An asynchronous variant of TcpClient and TcpListener for .NET Standard.
Stars: ✭ 125 (-22.84%)
Mutual labels:  tcp, tcp-server, tcp-client
Easytcp
Simple framework for TCP clients and servers. Focused on performance and usability.
Stars: ✭ 60 (-62.96%)
Mutual labels:  tcp, tcp-server, tcp-client
QTcpSocket
A simple Qt client-server TCP architecture to transfer data between peers
Stars: ✭ 62 (-61.73%)
Mutual labels:  tcp, tcp-server, tcp-client
network
exomia/network is a wrapper library around System.Socket for easy and fast TCP/UDP client & server communication.
Stars: ✭ 18 (-88.89%)
Mutual labels:  tcp, tcp-server, tcp-client
tcp server client
A thin and simple C++ TCP client server
Stars: ✭ 124 (-23.46%)
Mutual labels:  tcp, tcp-server, tcp-client
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (-58.64%)
Mutual labels:  tcp, tcp-server, tcp-client
Simplenet
An easy-to-use, event-driven, asynchronous network application framework compiled with Java 11.
Stars: ✭ 164 (+1.23%)
Mutual labels:  tcp, tcp-server, tcp-client
Hprose Nodejs
Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js
Stars: ✭ 297 (+83.33%)
Mutual labels:  tcp, tcp-server, tcp-client
Bizsocket
异步socket,对一些业务场景做了支持
Stars: ✭ 469 (+189.51%)
Mutual labels:  tcp, tcp-server, tcp-client
React Native Tcp Socket
React Native TCP socket API for Android, iOS & macOS with client SSL/TLS support
Stars: ✭ 112 (-30.86%)
Mutual labels:  tcp, tcp-server, tcp-client

simpleTCP

simpleTCP is a minimal non-blocking TCP server written for Python 3. It is licensed under the GNU Affero General Public License, Version 3.

Installation

simpleTCP is no longer available on PyPI. To install, run python3 setup.py install.

simpleTCP is written in pure Python 3. It has no external dependencies.

Quick Start

simpleTCP just requires that you specify:

  • the mode (local or public) of your server
    • your server can also be bound to a specific IP address
  • the port of your server
  • what happens when your server receives data

For example, here's an echo server:

from simpletcp.tcpserver import TCPServer

def echo(ip, queue, data):
    queue.put(data)

server = TCPServer("localhost", 5000, echo)
server.run()

Callback functions

echo is the server's callback function. This function is called whenever the server receives data.

Callback functions should take three arguments:

  1. ip: The IP address that the data was received from.
  2. queue: This is a queue.Queue object. Any data put into this queue will be asynchronously sent back to the socket it was received from. In this case, our server echoes all data it receives, so we just put all received data right back into this queue with queue.put(data).
  3. data: This is the data that the server received. It is a string of bytes. Its type is bytes.

The TCPServer itself

The TCPServer constructor takes three arguments:

  1. The mode. There are two special modes: "localhost" and "public". They are aptly named --- "localhost" means run the server on 127.0.0.1. Therefore, the server is only visible on the machine on which it is running. "public" means run the server on 0.0.0.0 --- make it visible to anything that can see the machine on which it is running. If mode is not "localhost" or "public", then it is interpreted as an IP address.
  2. The port. For development, pick a high (four-digit) number.
  3. The callback function. This function is called whenever the server receives data.

Sending data to the server

To send data to the server, create a ClientSocket and send away!

from simpletcp.clientsocket import ClientSocket

s1 = ClientSocket("localhost", 5000, single_use=False)
response = s1.send("Hello, World!")

Examples

Examples can be found in the /examples folder.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].