Skip to content
Discussion options

You must be logged in to vote

WebSocketResponse handles a WebSocket on an incoming request; the listening port belongs to a site. One aiohttp process can run more than one TCPSite:

from aiohttp import web

runner = web.AppRunner(app)
await runner.setup()
public_site = web.TCPSite(runner, "0.0.0.0", 8080)
peer_site = web.TCPSite(runner, "10.0.0.5", 8081)
await public_site.start()
await peer_site.start()
# Later: await runner.cleanup()

I tested WebSocket handshakes through both sites with aiohttp 3.14.5. One important detail for your security goal: when both sites use the same application/runner, all its routes are reachable through both ports. For peer-only routes, put them in a separate application with its own AppRunner

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Zhaoxun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants