Skip to main content

Data Transfer Protocol Library

dtplib is a cross platform networking library written in Python.

Source: https://github.com/WKHAllen/dtplib

Dependencies

Installation

$ pip install dtplib

Server

Creating a server

s = Server(onRecv=None, onConnect=None, onDisconnect=None, blocking=False, eventBlocking=False, recvDir=None, daemon=True, jsonEncode=False)

Create a server object.

onRecv is a function that will be called when a packet is received. It takes the following parameters: client socket, data, datatype (0: object, 1: file). onConnect is a function that will be called when a client connects. It takes the following parameters: client socket. onDisconnect is a function that will be called when a client disconnects. It takes the following parameters: client socket. If blocking is True, the start method will block until stopping. If eventBlocking is True, onRecv, onConnect, and onDisconnect will block when called. recvDir is the directory in which files will be put in when received. If daemon is True, all threads spawned will be daemon threads. If jsonEncode is True, packets will be encoded using json instad of pickle.

Starting the server

s.start(host=None, port=None)

Start the server. If host is not specified, it will default to socket.gethostname(). If port is not specified, it will default to 0, which represents an arbitrary unused port.

Stopping the server

s.stop()

Stop the server.

Check if the server is serving

s.serving()

Get the server's address

s.getAddr()

Get a client's address

s.getClientAddr(conn)

Get a client's address, providing the client socket object.

Get a list of a server's clients

s.getClients()

Remove a client

s.removeClient(conn)

Disconnect a client from the server, providing the client socket object.

Send data to a client

s.send(data, conn=None)

Send data to a client. conn is the client socket object to send the data to. If conn is None, data is sent to all clients.

Send a file or directory to a client

s.sendFile(path, conn=None)

Send a file or directory to a client. path is the path to the file or directory. conn is the client socket object to send the file or directory to. If conn is None, the file or directory is sent to all clients.

Server alternative

The dtplib server object can be used in a with statement.

with server(host, port, *args, **kwargs) as s:
    pass

host is the server IP address. port is the port number. args and kwargs will be passed to the Server class constructor.

Client

Creating a client

c = Client(onRecv=None, onDisconnected=None, blocking=False, eventBlocking=False, recvDir=None, daemon=True, jsonEncode=False)

Create a client object.

onRecv is a function that will be called when a packet is received. It takes the following parameters: data, datatype (0: object, 1: file). onDisconnected is a function that will be called when the server disconnects suddenly. It takes no parameters. If blocking is True, the connect method will block until disconnecting. If eventBlocking is True, onRecv and onDisconnected will block when called. recvDir is the directory in which files will be put in when received. If daemon is True, all threads spawned will be daemon threads. If jsonEncode is True, packets will be encoded using json instad of pickle.

Connecting to a server

c.connect(host, port)

Disconnecting from the server

c.disconnect()

Check if connected to a server

c.connected()

Get the client's address

c.getAddr()

Get the remote server's address

c.getServerAddr()

Send data to the server

c.send(data)

Send data to the server, providing the data to be sent.

Send a file or directory to the server

c.sendFile(path)

Send a file or directory to the server, providing the path to the file or directory to be sent.

Client alternative

The dtplib client object can be used in a with statement.

with client(host, port, *args, **kwargs) as c:
    pass

host is the server IP address. port is the port number. args and kwargs will be passed to the Client class constructor.

Release files for dtplib 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for dtplib 1.2.1
File Interpreter ABI Platform
dtplib-1.2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / dtplib-1.2.1-py2.py3-none-any.whl

Download URL dtplib-1.2.1-py2.py3-none-any.whl
Size 8.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c1a965ab0dedef57bdb6a028bd3aeb0e775c97594194ca48eb841d5e6075a8c3
BLAKE2b-256 checksum
How to use checksums
7bdc94b0ba3e245eb94d17aab34d6fd33234bccfbf8abb13f85fb533ab49d2fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.8

Release history Release notifications | RSS feed

This release

1.2.1 This release

1 release file

1.2.0

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page