❔ WebSocketSharp and Azure Endpoint (Error 1006)
Summary:
1) I create a
2) Use the returned
3) Attempt to perform
However,
My actual code:
I am new to azure. How can I debug?
1) I create a
UnityWebRequestUnityWebRequest which is used to call request.SendWebRequest()request.SendWebRequest(). 2) Use the returned
request.downloadHandler.textrequest.downloadHandler.text to create a ws = new WebSocket(request.downloadHandler.text, "json.webpubsub.azure.v1");ws = new WebSocket(request.downloadHandler.text, "json.webpubsub.azure.v1");3) Attempt to perform
ws.Connect()ws.Connect()However,
ws.Connect()ws.Connect() never connects and instead always triggers OnClose()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();
} 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?