Cannot reconnect a WebSocket in WebGL

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

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp, unity

Research direction

Start with the Connect and Close entry points and the Update() call sequence described in the issue, then inspect the WebGL-specific WebSocket lifecycle. Reproduce opening, sending, closing, and reopening in a Unity WebGL build; done means the second Connect succeeds without the already-connected or connecting-state exception.

Written by the indexing model from the issue text.

Description

The sequence...

  • Opening a socket: Invoke() on a method calling await _webSock.Connect();
  • Sending messages: Calling _webSock.SendText(msg);
  • Closing the socket: Invoke() on a method calling await _webSock.Close();

Everything works fine.
All the calls are performed inside the Update() method.
The three calls are user-controlled. Hence, some seconds pass between them.

Now, trying to re-open the socket again with: Invoke() on a method calling await _webSock.Connect();
Work good in Unity Editor.
Fails in WebGL with error:

WebSocketInvalidStateException: WebSocket is already connected or in connecting state.
  at NativeWebSocket.WebSocket.Connect () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
 
(Filename: currently not available on il2cpp Line: -1)
Dominant language
C#
Stars
1.7k
Forks
206
PR merge metrics
No merged PRs in 30d

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.

More from endel/NativeWebSocket

All issues in endel/NativeWebSocket

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.