Hi,
I'm trying to implement a WebPubSub client in a video game using UE4 game engine's FWebSocketsModule C++ class, which links with libWebSockets library.
When I use a "Client Access URL" from Azure WebPubSub Dashboard's "Client URL Generator", and open the WebSocket with
FWebSocketsModule::Get().CreateWebSocket(PubSubURL, TEXT(""))
everything works fine. The game code successfully connects to the WebSocket and can receive PubSub events a subscriber on the hub.
However, when I don't use this "Client URL Generator" devtool to generate the WebSocket url, but instead generate it using the WebPubSub SDK to in a C# app:
var serviceClient = new WebPubSubServiceClient(Connections.ConnectionString, TEXT("Hub"));
var connectURL = serviceClient.GenerateClientAccessUri(userId: "player1234");
return connectURL.ToString();
where Connections.ConnectionString is the "ConnectString" provided in the WebPubSub dashboard, then my game's
FWebSocketsModule::Get().CreateWebSocket(PubSubURL, TEXT(""))
operation fails. Since FWebSocketsModule uses a binary library, I don't get complete insight into the failure cause, though I do know I receive a "401 Unauthorized" response from the WebSocket server, so I assume the WebSocket upgrade failed. Unfortunately, since the Azure PubSub service uses wss/secured WebSockets, I can't use WireShark to review the WebSocket upgrade handshaking.
Further confounding the issue, however, is that, if I use that exact same PubSubUrl I generated to open a connection from a C# using the ClientWebSocket() object, the WebSocket connection succeeds, and the PubSub functionality works properly.
using (var client = new WebsocketClient(url, () =>
{
var inner = new ClientWebSocket();
return inner;
}))
Summary:
- If I use the PubSub dashboards "Client URL Generator" to get a URL, the FWebSocketsModule websocket library connects to Azure WebPubSub and works properly
2) If I instead generate the websocket URL using WebPubSubServiceClient::GenerateClientAccessUri() per microsoft samples, the FWebSocketsModule websocket fails with "401 Unauthorized" error.
3) However, that exact same websocket URL works properly when used in a C# program (based on Microsoft samples) and WebsocketClient object.
Anyone have an idea what I'm doing wrong?
Thanks!
-greg