File: README.md

package info (click to toggle)
python-autobahn 17.10.1%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,452 kB
  • sloc: python: 22,598; javascript: 2,705; makefile: 497; sh: 3
file content (37 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Running multiple WebSocket services

This example demonstrates how to run multiple, different WebSocket services in one server on one port.


## Service Wrapper

This example shows how to choose the service to be used in `onConnect` of a wrapping `webSocketServerProtocol`.

This method has the advantage of being able to choose the service to be used using any information from the initial WebSocket opening handshake.

Run the server

	python server1.py

Run the client with different WebSocket URLs:

	python client.py ws://127.0.0.1:9000/echo1
	python client.py ws://127.0.0.1:9000/echo2


## Twisted Web

AutobahnPython based WebSocket servers can run under Twisted Web as a resource.

This is quite flexible and allows to mix different services like static file serving, WSGI servers (like Flask) and AutobahnPython-based WebSocket or WAMP servers all under one server and port.

Run the server

	python server2.py

Run the client with different WebSocket URLs:

	python client.py ws://127.0.0.1:9000/echo1
	python client.py ws://127.0.0.1:9000/echo2
	
This method has the disadvantage compared to the other option in that you cannot choose your service dependent on WebSocket specific details from the WebSocket opening handshake like i.e. WebSocket subprotocol.