C#C
C#3y ago
J.

❔ WebSocketSharp and Azure Endpoint (Error 1006)

Summary:

1) I create a
UnityWebRequest
which is used to call
request.SendWebRequest()
.

2) Use the returned
request.downloadHandler.text
to create a
ws = new WebSocket(request.downloadHandler.text, "json.webpubsub.azure.v1");


3) Attempt to perform
ws.Connect()


However,
ws.Connect()
never connects and instead always triggers
OnClose()
instead, citing error 1006.

My actual code:

   private IEnumerator ConnectToAzure()
    {
        string url = "https://myurl.azurewebsites.net/api/createprivatemessage?code=mycode";

        InputData inputData = new InputData { sender = playFabId };
        string data = JsonConvert.SerializeObject(inputData);
        UnityWebRequest request = new UnityWebRequest(url, "POST");
        byte[] bodyRaw = Encoding.UTF8.GetBytes(data);
        request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
        request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");

        yield return request.SendWebRequest();

        if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
        {
            Debug.LogError(request.error);
        }
        else
        {
            ws = new WebSocket(request.downloadHandler.text, "json.webpubsub.azure.v1");
            IsWebSocketUrlReachable(url);
            // Set the WebSocket headers
            // client.SetCredentials(azureConnection, "", false);
            ws.OnOpen += OnWebSocketOpen;
            ws.OnMessage += OnMessage;
            ws.OnError += OnError;
            ws.OnClose += OnClose;
            ws.Connect();
            if(ws.ReadyState!= WebSocketState.Open) {
                Debug.Log("WebSocket was NOT opened. Something went wrong during initial connection in ConnectToAzure()");
            }
        }
        request.Dispose();
    }


I am new to azure. How can I debug?
Was this page helpful?