sta / sta/websocket-sharp

An exception has occurred while connecting. CloseStatus of 1006 Abnormal

Open
#189 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

Ok, i've started using websocket at work and for some reason it's not working.

The same code works when I place the class in my server code.

An exception has occurred while connecting.
UnityEngine.Debug:Log(Object)
ODDFramework.Analytics:Ws_OnClose(Object, CloseEventArgs) (at Assets/ODDFramework/Analytics/Analytics.cs:39)
WebSocketSharp.Ext:Emit(EventHandler`1, Object, CloseEventArgs)
WebSocketSharp.WebSocket:close(CloseEventArgs, Boolean, Boolean, Boolean)
WebSocketSharp.WebSocket:processException(Exception, String)
WebSocketSharp.WebSocket:connect()
WebSocketSharp.WebSocket:Connect()
ODDFramework.Analytics:.ctor(String, Int32, String, String) (at Assets/ODDFramework/Analytics/Analytics.cs:30)
AnalyticsExample:Start() (at Assets/ODDFramework/Examples/Analytics Example/AnalyticsExample.cs:12)

Server:

server = new WebSocketServer("ws://localhost:" + port.ToString());
server.AddWebSocketService<AnalyticsBehaviour>("/analytics", () =>
{
    return new AnalyticsBehaviour(analytics);
});
server.AuthenticationSchemes = WebSocketSharp.Net.AuthenticationSchemes.Basic;
server.UserCredentialsFinder = id =>
{

    foreach (KeyValuePair<string, string> bundle in bundles) {

        if (bundle.Key == id.Name) 
        {
            return new WebSocketSharp.Net.NetworkCredential(bundle.Key, bundle.Value);
        }

    }

    return null;

};

server.Start();

Client:

ws = new WebSocket(string.Format("ws://{0}:{1}/analytics", host, port.ToString()));
ws.OnMessage += Ws_OnMessage;
ws.OnError += Ws_OnError;
ws.OnClose += Ws_OnClose; ws.OnOpen += Ws_OnOpen;
ws.OnOpen += Ws_OnOpen;
ws.SetCredentials(bundleIdentifier, password, true);
ws.ConnectAsync();

The code works fine within the same console app it just doesn't work when I take the client code and put it in Unity. I tried the sockpol.exe thing but that didn't work either.

I have this working at home and I'm fairly certain my dev environment is similar.

I'm using a compiled version of the github code since I realised the asset store version is old, but I've tried the asset store version also and it doesn't work, same error.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Unity stack trace at Assets/ODDFramework/Analytics/Analytics.cs lines 30 and 39, then inspect the WebSocket constructor and ConnectAsync call shown in the issue. Compare that client with the version that works in the console app and reproduce the connection attempt in Unity. Done means identifying the Unity-specific cause of close status 1006 and verifying a successful connection.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
game-dev, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.