Skip to main content

A small tcp package to send and receive tcp messages.

Project description

Travis ReadTheDocs Coveralls

pyTCP

A small tcp package to send and receive tcp messages.

Installation

pip install pyTCP

Usage

synchronous:

from pyTCP import EchoServer, TcpClient

echo_server = EchoServer("127.0.0.1", 12345)
echo_server.start_server()
client = TcpClient("127.0.0.1", 12345)
client.connect()

data_to_send = b"Test message"
client.send(data_to_send)
client_received = client.receive()
server_received = echo_server.last_received
assert data_to_send == client_received
assert data_to_send == server_received

# or with a delimiter
data_to_send = b"Test\nmessage"
client.send(data_to_send)
client_received = client.receive_until(delimiter=b'\n')
assert b"Test" == client_received

echo_server.stop_server()
client.close()

async:

import asyncio

from pyTCP import AsyncTcpClient, EchoServer


async def main():
    echo_server = EchoServer("127.0.0.1", 12345)
    echo_server.start_server()
    client = AsyncTcpClient("127.0.0.1", 12345)
    await client.connect()

    data_to_send = b"Test message"
    await client.send(data_to_send)
    data = await client.receive()
    assert data == data_to_send

    echo_server.stop_server()
    client.close()


if __name__ == "__main__":
    asyncio.run(main())

Note

This project has been set up using PyScaffold 3.2.3. For details and usage information on PyScaffold see https://pyscaffold.org/.

Project details


Release history Release notifications

This version

0.1

Download files

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

Files for pyTCP, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size pyTCP-0.1-py3-none-any.whl (8.0 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page