simple-sock


Namesimple-sock JSON
Version 0.1.4 PyPI version JSON
download
home_pageNone
SummaryA Python library for simplified network and HTTP connections management.
upload_time2024-07-21 02:29:55
maintainerNone
docs_urlNone
authorLeonardo Oliveira
requires_python>=3.6
licenseNone
keywords simplified socket simple sock network easy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # simple-sock

`simple-sock` offers a straightforward interface for TCP and UDP sockets in Python, with support for optional SSL/TLS encryption and routing for TCP connections.

## Basic Usage

### Basic TCP Server

```python
from simple_sock import Server

app = Server()

@app.tcp_listen()
def handle_tcp(data):
    print("Received:", data.msg)
    return "Response from TCP server"

app.run("localhost", 5454)  # Optional parameters: keyfile=None, certfile=None, timeout=0, buffer_size=1024
```

### TCP Server with Routing

```python
from simple_sock import Server

app = Server()

@app.parse_route
def parse_route(data):
    return data.msg.split()[0]

@app.tcp_listen()
def default_route(data):
    return "Default response"

@app.tcp_listen("route1")
def route1(data):
    return "Response for route1"

app.run("localhost", 5454)
```

### Basic TCP Client

```python
from simple_sock import Client

client = Client()
client.connect("localhost", 5454)  # Optional parameters: udp=False, tls=False
client.send("Hello from TCP client")
response = client.recv()
print(response)
client.close()
```

### UDP Support

UDP usage is similar; use `@app.udp_listen()` for servers and set `udp=True` for clients. Example:

```python
# UDP Server
app = Server(udp=True)
@app.udp_listen()
def handle_udp(data):
    print("Received:", data.msg)
    return "Response from UDP server"
app.run("localhost", 5455")

# UDP Client
client.connect("localhost", 5455, udp=True)
client.send("Hello from UDP client")
response, addr = client.recv()
print(response)
client.close()
```

## License

MIT License

## Contact

For questions, contact Leonardo Oliveira at [email](mailto:lo570354@gmail.com).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "simple-sock",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "simplified, socket, simple, sock, network, easy",
    "author": "Leonardo Oliveira",
    "author_email": "lo570354@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/01/7f/9d167fc5e22ade4de2cb2c4e714578ecb0c36c2b23d2f33cad3d7e54244e/simple_sock-0.1.4.tar.gz",
    "platform": null,
    "description": "# simple-sock\r\n\r\n`simple-sock` offers a straightforward interface for TCP and UDP sockets in Python, with support for optional SSL/TLS encryption and routing for TCP connections.\r\n\r\n## Basic Usage\r\n\r\n### Basic TCP Server\r\n\r\n```python\r\nfrom simple_sock import Server\r\n\r\napp = Server()\r\n\r\n@app.tcp_listen()\r\ndef handle_tcp(data):\r\n    print(\"Received:\", data.msg)\r\n    return \"Response from TCP server\"\r\n\r\napp.run(\"localhost\", 5454)  # Optional parameters: keyfile=None, certfile=None, timeout=0, buffer_size=1024\r\n```\r\n\r\n### TCP Server with Routing\r\n\r\n```python\r\nfrom simple_sock import Server\r\n\r\napp = Server()\r\n\r\n@app.parse_route\r\ndef parse_route(data):\r\n    return data.msg.split()[0]\r\n\r\n@app.tcp_listen()\r\ndef default_route(data):\r\n    return \"Default response\"\r\n\r\n@app.tcp_listen(\"route1\")\r\ndef route1(data):\r\n    return \"Response for route1\"\r\n\r\napp.run(\"localhost\", 5454)\r\n```\r\n\r\n### Basic TCP Client\r\n\r\n```python\r\nfrom simple_sock import Client\r\n\r\nclient = Client()\r\nclient.connect(\"localhost\", 5454)  # Optional parameters: udp=False, tls=False\r\nclient.send(\"Hello from TCP client\")\r\nresponse = client.recv()\r\nprint(response)\r\nclient.close()\r\n```\r\n\r\n### UDP Support\r\n\r\nUDP usage is similar; use `@app.udp_listen()` for servers and set `udp=True` for clients. Example:\r\n\r\n```python\r\n# UDP Server\r\napp = Server(udp=True)\r\n@app.udp_listen()\r\ndef handle_udp(data):\r\n    print(\"Received:\", data.msg)\r\n    return \"Response from UDP server\"\r\napp.run(\"localhost\", 5455\")\r\n\r\n# UDP Client\r\nclient.connect(\"localhost\", 5455, udp=True)\r\nclient.send(\"Hello from UDP client\")\r\nresponse, addr = client.recv()\r\nprint(response)\r\nclient.close()\r\n```\r\n\r\n## License\r\n\r\nMIT License\r\n\r\n## Contact\r\n\r\nFor questions, contact Leonardo Oliveira at [email](mailto:lo570354@gmail.com).\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python library for simplified network and HTTP connections management.",
    "version": "0.1.4",
    "project_urls": null,
    "split_keywords": [
        "simplified",
        " socket",
        " simple",
        " sock",
        " network",
        " easy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e856f1eb9f2ea643d164ce78aeb7f3165c0762938200c078341b23488566fb68",
                "md5": "cf39fadb51b4ebb4e1f61e2ee1003c63",
                "sha256": "bc94345cb073ab1d5639f9174da0814b4a2cf035f5d51dd80be4931bb3dd4a52"
            },
            "downloads": -1,
            "filename": "simple_sock-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cf39fadb51b4ebb4e1f61e2ee1003c63",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4397,
            "upload_time": "2024-07-21T02:29:54",
            "upload_time_iso_8601": "2024-07-21T02:29:54.520353Z",
            "url": "https://files.pythonhosted.org/packages/e8/56/f1eb9f2ea643d164ce78aeb7f3165c0762938200c078341b23488566fb68/simple_sock-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "017f9d167fc5e22ade4de2cb2c4e714578ecb0c36c2b23d2f33cad3d7e54244e",
                "md5": "80ddcd8201acdcfbf5b9b17663cac8dd",
                "sha256": "7e8aa7de7bfa7434d8b53c31047ce9f0fdc9da7778a97c69439a6431d4150122"
            },
            "downloads": -1,
            "filename": "simple_sock-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "80ddcd8201acdcfbf5b9b17663cac8dd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4590,
            "upload_time": "2024-07-21T02:29:55",
            "upload_time_iso_8601": "2024-07-21T02:29:55.938967Z",
            "url": "https://files.pythonhosted.org/packages/01/7f/9d167fc5e22ade4de2cb2c4e714578ecb0c36c2b23d2f33cad3d7e54244e/simple_sock-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-21 02:29:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "simple-sock"
}
        
Elapsed time: 0.28488s