2017-05-21 03:14:58 -07:00
|
|
|
import os
|
2021-11-23 23:00:25 +02:00
|
|
|
import socket
|
|
|
|
|
|
|
|
from sanic import Sanic, response
|
|
|
|
|
2017-05-21 03:14:58 -07:00
|
|
|
|
2021-12-24 00:30:27 +02:00
|
|
|
app = Sanic("Example")
|
2017-05-21 03:14:58 -07:00
|
|
|
|
2017-06-01 11:53:05 -07:00
|
|
|
|
2017-05-21 03:14:58 -07:00
|
|
|
@app.route("/test")
|
|
|
|
async def test(request):
|
|
|
|
return response.text("OK")
|
|
|
|
|
2021-11-23 23:00:25 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
server_address = "./uds_socket"
|
2017-05-21 03:14:58 -07:00
|
|
|
# Make sure the socket does not already exist
|
|
|
|
try:
|
2021-11-23 23:00:25 +02:00
|
|
|
os.unlink(server_address)
|
2017-05-21 03:14:58 -07:00
|
|
|
except OSError:
|
2021-11-23 23:00:25 +02:00
|
|
|
if os.path.exists(server_address):
|
|
|
|
raise
|
2017-05-21 03:14:58 -07:00
|
|
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
|
|
sock.bind(server_address)
|
|
|
|
app.run(sock=sock)
|