diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..37f9879 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: cirospaciari diff --git a/README.md b/README.md index c358842..6409ba4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ +

@@ -102,6 +103,33 @@ app.listen(3000, lambda config: print("Listening on port http://localhost:%d now app.run() ``` +WebSockets +```python +from socketify import App, AppOptions, OpCode, CompressOptions + +def ws_open(ws): + print('A WebSocket got connected!') + ws.send("Hello World!", OpCode.TEXT) + +def ws_message(ws, message, opcode): + #Ok is false if backpressure was built up, wait for drain + ok = ws.send(message, opcode) + +app = App() +app.ws("/*", { + 'compression': CompressOptions.SHARED_COMPRESSOR, + 'max_payload_length': 16 * 1024 * 1024, + 'idle_timeout': 12, + 'open': ws_open, + 'message': ws_message, + 'drain': lambda ws: print('WebSocket backpressure: %i' % ws.get_buffered_amount()), + 'close': lambda ws, code, message: print('WebSocket closed') +}) +app.any("/", lambda res,req: res.end("Nothing to see here!'")) +app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % (config.port))) +app.run() +``` + We have more than 20 examples [click here](https://github.com/cirospaciari/socketify.py/tree/main/examples) for more ## Build local from source @@ -126,3 +154,8 @@ I'm a Brazilian consulting & contracting company dealing with anything related w Don't hesitate sending a mail if you are in need of advice, support, or having other business inquiries in mind. We'll figure out what's best for both parties. Special thank's to [uNetworking AB](https://github.com/uNetworking) to develop [uWebSockets](https://github.com/uNetworking/uWebSockets), [uSockets](https://github.com/uNetworking/uSockets) and allow us to bring this features and performance to Python and PyPy + +## Sponsors +If you like to see this project thrive, you can sponsor us on GitHub too. We need all the help we can get + +