Skip to main content

Multithreaded TCP server/client

Project description

Sockdot

simplified tcp networking library

note: This is not a websocket i'd write a little peice of introduction here, with a little bit of shit :D documentation would be ready in a while

Installation

pip install sockdot

Usage

server.py

from sockdot import Server
from sockdot.events import Event

serverevents = Event()
server = Server(debug=True)

@serverevents.event
def on_data_recieved(client, data):
	print("recieved:", data)
	server.send(client, f"you said {data}")

@serverevents.event
def on_connection_open(client):
	print(f"client {client} joined")

@serverevents.event
def on_connection_close(client):
	print(client, "closed connection")

@serverevents.event
def on_server_destruct():
	print("server shutdown")

@serverevents.event
def on_error(exception, message):
	pass

@serverevents.event
def on_port_changed(port):
	print("server changed port to", port)

@serverevents.event
def on_running_changed(running):
	print("server is running" if running else "server is not running")

server.updateevent(serverevents)
server.run()

client.py

import time
from sockdot import Client
from sockdot.events import Event

clientevents = Event()
client = Client(host="localhost", debug=True)

@clientevents.event
def on_data_recieved(data):
	print(f"got {data} from server")

@clientevents.event
def on_connected_changed(connected):
	pass

@clientevents.event
def on_error(exception, message):
	print(f"error {exception} occured, message:", message)

@clientevents.event
def on_host_changed(host):
	pass

@clientevents.event
def on_port_changed(port):
	pass

@clientevents.event
def on_handshake_started():
	pass

@clientevents.event
def on_handshake_ended(result):
	pass

client.updateevent(clientevents)
client.connect()

# hold on until client gets connected to server
while True:
	if client.connected:
		break

# send i for i in range 10
for i in range(10):
	client.send(str(i))
	time.sleep(4)
client.close()

Project details


Download files

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

Files for sockdot, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size sockdot-1.0.0-py3-none-any.whl (5.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size sockdot-1.0.0.tar.gz (4.1 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 DigiCert DigiCert EV certificate StatusPage StatusPage Status page