The control channel is used to setup a WebSocket to listen the incoming connection. It allows up to 25 concurrent listeners for one hybrid connection. The control channel takes response from step #1 to #5 in following architecture.
When a sender open a new connection. The control channel chose one active listener. The active listener will setup a new WebSocket as rendezvous channel. The messages will be transferred via this rendezvous channel. The rendezvous channel takes response from step #6 to #9 in above architecture.
Below is a simple Python application to realize control channel and rendezvous channel
Following is control channel’s on_message callback function. The sender connection on the control channel will contains a url. The url is the rendezvous url need to be established.
The callback function will use create_connection to create a new WebSocket on this rendezvous url. After finish creating rendezvous channel, the WebSocket will call recv() to receive messages.
def on_message(ws, message):
data = json.loads(message)
url = data["accept"]["address"]
ws = None
ws = create_connection(url)
connected = ws.connected
receive_msg = ws.recv()
except Exception, ex:
Some times, the callback function will be triggered even sender dose not send any message. It is actually control channel notifications. For example, if the relay server wait long time and can’t get response from listener, it will send a “listener not response immediately” notification to listener side when listener recover.