kopia lustrzana https://github.com/cirospaciari/socketify.py
Merge branch 'main' of https://github.com/cirospaciari/socketify.py
commit
537604008e
|
@ -0,0 +1 @@
|
|||
github: cirospaciari
|
33
README.md
33
README.md
|
@ -8,6 +8,7 @@
|
|||
<a href="https://github.com/cirospaciari/socketify.py/actions/workflows/macos.yml" target="_blank"><img src="https://github.com/cirospaciari/socketify.py/actions/workflows/macos.yml/badge.svg" /></a>
|
||||
<a href="https://github.com/cirospaciari/socketify.py/actions/workflows/linux.yml" target="_blank"><img src="https://github.com/cirospaciari/socketify.py/actions/workflows/linux.yml/badge.svg" /></a>
|
||||
<a href="https://github.com/cirospaciari/socketify.py/actions/workflows/windows.yml" target="_blank"><img src="https://github.com/cirospaciari/socketify.py/actions/workflows/windows.yml/badge.svg" /></a>
|
||||
<a href="https://github.com/sponsors/cirospaciari/" target="_blank"><img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&link=https://github.com/sponsors/cirospaciari"/></a>
|
||||
</p>
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
<a href="https://github.com/sponsors/cirospaciari/" target="_blank"><img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&link=https://github.com/sponsors/cirospaciari"/></a>
|
||||
|
|
Ładowanie…
Reference in New Issue