endel / NativeWebSocket

🔌 WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP)
Other
1.12k stars 153 forks source link

Using ClientWebSocket through a proxy #93

Open Robert-96 opened 7 months ago

Robert-96 commented 7 months ago

Did anyone manage to use the NativeWebSocket/ClientWebSocket through a proxy?

Basically I tried to set the Proxy property from the ClientWebSocketOptions but the client does't connect to the server. It's giving me a 'Unable to connect to the remote server' error.

Here's my code snippet:

var source = new CancellationTokenSource();
var token = source.Token;

var socket = new ClientWebSocket();
WebRequest.DefaultWebProxy = new WebProxy(proxyUrl, false); // I tried to set the DefaultWebProxy too, but I get the same error 
socket.Options.Proxy = new WebProxy(proxyUrl, false);

await socket.ConnectAsync(uri, token);

It works in .NET5 but not in Unity.

Any insights or suggestions on resolving this issue would be greatly appreciated.

daniel-do-MA commented 4 days ago

@Robert-96 did you find solution ?