Hybrid relay control & rendezvous channel of Python edition
Published Jan 22 2021 12:09 AM 1,943 Views

This article will introduce the difference between control channel and rendezvous channel. And code a simple python application to interpret its process.


Pre-requirement:  understand azure relay https://docs.microsoft.com/en-us/azure/azure-relay/relay-what-is-it


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


  1. Below code will create a control channel.

    wss_uri = 'wss://{0}/$hc/{1}?sb-hc-action=listen'.format(service_namespace, entity_path) + '&sb-hc-token=' + urllib.quote(token)

    ws = WebSocketApp(wss_uri,





  1. 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

        if connected:

            receive_msg = ws.recv()

            //process message




     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.

Version history
Last update:
‎Jan 22 2021 12:33 AM
Updated by: