https://github.com/dan5py/socketsc
Python library for creating socket clients and servers.
https://github.com/dan5py/socketsc
client python server socket
Last synced: 11 months ago
JSON representation
Python library for creating socket clients and servers.
- Host: GitHub
- URL: https://github.com/dan5py/socketsc
- Owner: dan5py
- License: mit
- Created: 2023-03-06T13:08:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T13:25:32.000Z (over 3 years ago)
- Last Synced: 2025-03-01T16:26:14.094Z (over 1 year ago)
- Topics: client, python, server, socket
- Language: Python
- Homepage: https://socketsc.readthedocs.io/en/latest/
- Size: 53.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://pypi.org/project/socketsc/)
[](https://pypi.org/project/socketsc/)
[](https://pypi.org/project/socketsc/)
[](https://socketsc.readthedocs.io/en/latest/?badge=latest)
[](https://pypi.org/project/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)
```