Metadata-Version: 2.1
Name: socketsc
Version: 1.5.1
Summary: Simple socket library for client/server with events management.
Home-page: https://gitlab.com/dan5py/socketsc
Author: Dan5py
License: MIT
Keywords: server client socket event tcp
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires: wheel
Requires-Python: >=3.8.0
Description-Content-Type: text/markdown
License-File: LICENSE

!["socketsc"](https://i.imgur.com/aVhWeoh.png)

[![License](https://img.shields.io/pypi/l/socketsc)](https://pypi.org/project/socketsc/)
[![Version](https://img.shields.io/pypi/v/socketsc)](https://pypi.org/project/socketsc/)
[![Python](https://img.shields.io/pypi/pyversions/socketsc)](https://pypi.org/project/socketsc/)
[![Documentation Status](https://readthedocs.org/projects/socketsc/badge/?version=latest)](https://socketsc.readthedocs.io/en/latest/?badge=latest)
[![Downloads](https://img.shields.io/pypi/dm/socketsc)](https://pypi.org/project/socketsc/)
[![Issues](https://img.shields.io/gitlab/issues/open/dan5py/socketsc)](https://gitlab.com/dan5py/socketsc/-/issues)

## Installation

```bash
pip install socketsc
```

## Usage

Simple client and server implementation.

### Server

```python
import socketsc

server = socketsc.SocketServer(("localhost", 8080), address_family=socketsc.AF_INET, sock_type=socketsc.SOCK_TCP)

print("Server listening on port 8080")

def on_question(socket: socketsc.ServerSocketWrapper, data):
    print(f"Received {data} from {socket.client_address}")
    socket.emit("answer", "1")

server.on("question", on_question)
server.serve()
```

### Client

```python
import socketsc

server_address = ("localhost", 8080)
sock = socketsc.SocketClient(server_address, address_family=socketsc.AF_INET, sock_type=socketsc.SOCK_TCP)


def on_answer(conn: socketsc.SocketClient, data):
    print(f"Server responded with {data}")


sock.emit("question", "0")
sock.on("answer", on_answer)
```
