Unify SocketServer Implementations based on a Session Model
Project description
pyserve
Unify SocketServer Implementations based on a Session Model
Install
pip install pyserve3
Example
from pyserve import *
from typing import Optional
class EchoServer(Session):
def connection_made(self, addr: Address, writer: Writer):
print('connection made!', addr, writer)
self.addr = addr
self.writer = writer
def data_recieved(self, data: bytes):
print(f'recieved {data!r} from {self.addr}')
self.writer.write(data)
self.writer.close()
def connection_lost(self, err: Optional[Exception]):
print('connection lost!', self.addr, err)
# run sync
# listen_udp_threaded(('127.0.0.1', 8000), EchoServer)
# listen_tcp_threaded(('127.0.0.1', 8000), EchoServer)
# run async
import asyncio
# asyncio.run(listen_udp_async(('127.0.0.1', 8000), EchoServer))
asyncio.run(listen_tcp_async(('127.0.0.1', 8000), EchoServer))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyserve3-0.0.4.tar.gz
(6.2 kB
view details)
File details
Details for the file pyserve3-0.0.4.tar.gz
.
File metadata
- Download URL: pyserve3-0.0.4.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17b6a4d890f39b5b5437ace04cb22c641f2fc7fd823466d9c73f4465e3645a37 |
|
MD5 | 8a456137e4e0e6381bcb0afb12331c54 |
|
BLAKE2b-256 | e84ef25d5b97f1b0bb54eecf6ae8da745254ab5818a4fcdd8c0e58dedd496df1 |