kopia lustrzana https://github.com/cirospaciari/socketify.py
add more examples and fixes
rodzic
eef417be32
commit
8796194a2c
|
@ -34,6 +34,6 @@ app.ws("/*", {
|
|||
'open': ws_open,
|
||||
'drain': ws_drain
|
||||
})
|
||||
app.any("/", lambda res,req: res.end("Nothing to see here!'"))
|
||||
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()
|
|
@ -0,0 +1,26 @@
|
|||
from socketify import App, AppOptions, OpCode, CompressOptions
|
||||
|
||||
def ws_open(ws):
|
||||
print('A WebSocket got connected!')
|
||||
#Let this client listen to topic "broadcast"
|
||||
ws.subscribe('broadcast')
|
||||
|
||||
def ws_message(ws, message, opcode):
|
||||
#Ok is false if backpressure was built up, wait for drain
|
||||
ok = ws.send(message, opcode)
|
||||
#Broadcast this message
|
||||
ws.publish('broadcast', 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,
|
||||
# The library guarantees proper unsubscription at close
|
||||
'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()
|
|
@ -0,0 +1,13 @@
|
|||
from socketify import App
|
||||
def home(res, req):
|
||||
res.write('<html><h1>')
|
||||
res.write('Your proxied IP is: %s' % res.get_proxied_remote_address())
|
||||
res.write('</h1><h1>')
|
||||
res.write('Your IP as seen by the origin server is: %s' % res.get_remote_address())
|
||||
res.end('</h1></html>')
|
||||
|
||||
|
||||
app = App()
|
||||
app.get("/*", home)
|
||||
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
|
||||
app.run()
|
|
@ -26,6 +26,6 @@ app.ws("/*", {
|
|||
'drain': lambda ws: print('WebSocket backpressure: %s', ws.get_buffered_amount()),
|
||||
'close': lambda ws, code, message: print('WebSocket closed')
|
||||
})
|
||||
app.any("/", lambda res,req: res.end("Nothing to see here!'"))
|
||||
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()
|
|
@ -28,6 +28,6 @@ app.ws("/*", {
|
|||
'drain': lambda ws: print('WebSocket backpressure: %s', ws.get_buffered_amount()),
|
||||
'close': lambda ws, code, message: print('WebSocket closed')
|
||||
})
|
||||
app.any("/", lambda res,req: res.end("Nothing to see here!'"))
|
||||
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()
|
|
@ -19,6 +19,6 @@ app.ws("/*", {
|
|||
'drain': lambda ws: print('WebSocket backpressure: %s', ws.get_buffered_amount()),
|
||||
'close': lambda ws, code, message: print('WebSocket closed')
|
||||
})
|
||||
app.any("/", lambda res,req: res.end("Nothing to see here!'"))
|
||||
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()
|
|
@ -40,7 +40,6 @@ app.ws("/*", {
|
|||
'message': ws_message,
|
||||
'upgrade': ws_upgrade
|
||||
})
|
||||
app.any("/", lambda res,req: res.end("Nothing to see here!'"))
|
||||
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()
|
Ładowanie…
Reference in New Issue