Unable to connect to websocket from Unity

Hi,

I am using trying to customise the Double 3 WebRTC application to run it from Unity. The original is at: https://glitch.com/~d3-webrtc-example and remix at: familiar-vaulted-rubidium .

It run fine on itself. I can also connect to the socket from a local website, connecting to “wss://familiar-vaulted-rubidium.glitch.me”. But connection fail from Unity (with error: System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
at System.Net.WebSockets.WebSocketHandle+…)

Connecting to test websocket “wss://echo.websocket.org” is successful, so would think the problem is related to options… which I would not know how to set.

Anyone able to help? That would just be awesome…

You might want to reach out to Glitch and make sure they do not throttle connections to the Unity server. For example, they don’t allow connections to gitlab.

support@glitch.com

Thanks @RiversideRocks. I took contact with support and they are investigating the issue. I haven’t made much progress but thought I’d post this here to clarify:

Bug: websocket connection on Glitch fails when requested from Unity (2019.4.9f1).

Two servers:
-A simple “one page websocket server” I run on my local network “pastoral-superficial-stoplight
-A working application remix running on Glitch “familiar-vaulted-rubidium

Two clients:
-simple websocket client (Chrome extension)
-Unity application

Results:


-simple websocket client can connect and communicate with local server (or remote test “wss://echo.websocket.org”)


-simple websocket client can connect and communicate with Application on Glitch (using socket “wss://familiar-vaulted-rubidium.glitch.me” - NOTE: is working using both ws or wss)


-Unity client can connect and communicate with local server (or remote test “wss://echo.websocket.org”).


-Unity client fail connecting to websocket on Glitch (using “wss://familiar-vaulted-rubidium.glitch.me”)

No one can help?

I’ll assume you did this, what did support say?

Hi there. Just heard back from support:

“I just got an update from the team. It looks like we are blocking Unity because the requests are missing a User-Agent header. Glitch does require that this information be present in order for your project to accept the requests.”

I am not 100% sure how this works, but there is a function meant to set the request header of the websocket client options (public void SetRequestHeader (string headerName, string headerValue);). But what would be the headername and headerValue?

How to get this information!?

UPDATE: finally! I have the socket opening… using: ws.Options.SetRequestHeader( “User-Agent”, “Unity3D”);

Now… let’s see if I can send and receive. :slight_smile:

6 Likes

Well I have tried using a header value for “User-Agent” both a real name of the application, and a spoof “curl” one. Neither worked.

It seem to work with any headerValue in my case, if the value is set for “User-Agent” headerName
What is the Unity error message? Was it:
somethingsomething<ParseAndValidateConnectResponseAsync>somethingsomething ?