Skip to main content

A universal communication engine

Project description

socket.engine

Installation

Python:

pip install socket.engine

This library requires Python3. It was tested extensively on Python 3.7.5 with Ubuntu 19.04.

How to use

Host

from socketengine import host

h = host()
h.start()

while True:
	data = h.get_ALL("test")

	if data is not None:
		for item in data:
			print(item)
			break

h.close()

Please Note: Starting a socket.engine socket in Python is a blocking action and will not finish until the socket is opened.

Client

from socketengine import client

c = client()
c.start()

c.write("test", "client is connected!")

c.close()

Socket.engine will automatically store the most recent piece of data received over a channel. This data is accessible via the get method. Socket.engine runs on a separate thread from the rest of your program and will therefore be constantly reading from the data socket.

Documentation

Host

Host Constructor:

host(addr='127.0.0.1', port=8080, timeout=2, size=256, open=True)
	addr = Address to host the socket connection
	port = Port connection to use with socket
	timeout = Sets the standard timeout of a socket (in seconds)
	size = Default read size of socket
	open = Open the socket automatically on connection (note: this does not "start" the socket thread)

Host Methods:

host.set_timeout(time):
	Sets the timeout of a socket (in seconds)
host.start():
	Starts the socket thread. SHOULD ONLY BE CALLED ONCE
host.get_ALL(channel):
	Reads all data from a specified channel. Returns a list of all responses (or [] if no responses)
host.getClients():
	Returns a list of connected clients as socket objects
host.writeLock_ALL(channel, data):
	Writes data on the specified channel to all clients. Uses a lock on each connection
host.write_ALL(channel, data):
	Writes data on the specified channel to all clients
host.writeImgLock_ALL(data): 
	Writes image data over the "image" channel to all clients. This method optimized for sending entire images. Uses a lock on each connection
host.writeImg_ALL(data): 
	Writes image data over the "image" channel to all clients. This method optimized for sending entire images.
host.close(): 
	Closes the connection with each client

Client

Client Constructor:

client(addr='127.0.0.1', port=8080, timeout=2, size=256, open=True)
	addr = Address the host is using
	port = Port connection on host
	timeout = Sets the standard timeout of a socket (in seconds)
	size = Default read size of socket
	open = Open the socket automatically on connection (note: this does not "start" the socket thread)

Client Methods:

client.set_timeout(time):
	Sets the timeout of a socket (in seconds)
client.start():
	Starts the socket thread. SHOULD ONLY BE CALLED ONCE
client.get(channel):
	Reads all data from a specified channel
client.writeLock(channel, data):
	Writes data on the specified channel. Uses a lock on each connection
client.write(channel, data): 
	Writes data on a specified channel
client.writeImgLock(data):
	Writes image data over the "image" channel. This method optimized for sending entire images. Uses a lock on each connection
client.writeImg(data):
	Writes image data over the "image" channel. This method optimized for sending entire images.
client.close():
	Closes the connection

Project details


Download files

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

Source Distribution

socket.engine-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

socket.engine-0.2.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file socket.engine-0.2.0.tar.gz.

File metadata

  • Download URL: socket.engine-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.5

File hashes

Hashes for socket.engine-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6c0e27e97d9552e2d96714b5a255e1ef7dd66bbf131db61f971c925c0c4536ec
MD5 2b721531c4a4344149b6ff7b337f4ff1
BLAKE2b-256 a8d5c2ef10032e950535c1746a40da52f34312e6c64051c081d152432a8f0bce

See more details on using hashes here.

File details

Details for the file socket.engine-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: socket.engine-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.5

File hashes

Hashes for socket.engine-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0379b66e0034eb8d098901a3e5f26f4540aa3b85c036b0a5e56090bd19b8f0b
MD5 d1acd174496ef690bb257d7126c56f79
BLAKE2b-256 5221b1cf83e2d109bb5f721694b7b2d9c88432b11434e9765be72f306c2119ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page