sta / sta/websocket-sharp

The header of a frame cannot be read from the stream

Open
#582 2 comments 1 reaction 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

This WebSocketException "The header of a frame cannot be read from the stream" is always thrown when closing the web socket client.

I have an example of a websocket client sending and receiving the same message from the backend.

WebSocketClient
using (var ws = new WebSocket ("wss://localhost:44398/ws"))
{
ws.OnMessage += (sender, e) =>
Console.WriteLine ("Received Message: " + e.Data);
ws.Connect ();
ws.Send ("Test Message");
Console.ReadKey();
}

Backend
It is an asp.net core web application which only receive the request from the WebSocketClient and it answers back with the same message.

It returns the message as expected, but then after entered any key to continue with the execution it fails and throws the above exception at the time of closing the web socket client.

Here is the the code if you would like to take a look.
https://github.com/juanrivera2306/WebSocketSample

There is a README.txt file with the instructions to run the example.

I really appreciate any help you can provide.

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 linked WebSocketSample repository and its README.txt, then reproduce the failure from WebSocketClient when the using block closes after Console.ReadKey(). Compare that close path with the backend's echoed-message behavior; done means the sample can close the client without the reported WebSocketException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.