OnMessage() running some code before Send() closes connection
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I have a switch setup so depending on what the incoming message from the client is my program will do different things. I pasted the code below, the case on top works fine, the one on bottom crashes and says connection is not open. I'd like to be able to process information and then send a message back to the client. I apologize if I'm an idiot and doing this completely wrong all together.
public class Website : WebSocketBehavior
{
protected override void OnMessage(MessageEventArgs e)
{
string msg = "";
switch (e.Data)
{
case var s when e.Data.StartsWith("~echo~"):
msg = e.Data.Substring(6);
Send(msg);
MessageBox.Show(msg);
break;
case var s when e.Data.StartsWith("~getid~"):
msg = e.Data.Substring(7);
MessageBox.Show(msg);
Send(msg);
break;
default:
break:
}
}
}
internal class WebSocketClass
{
internal void LoadWebSocketServer()
{
WebSocketServer wssv = new WebSocketServer("ws://localhost:7890");
wssv.AddWebSocketService<Website>("/Website");
wssv.Start();
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with WebSocketBehavior.OnMessage in the provided Website class and trace how Send is reached in each switch case. Then inspect LoadWebSocketServer and the WebSocketServer lifecycle to determine why the connection is closed before the second Send. Done means the requested message-processing flow sends a response without reporting that the connection is not open.
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
- Needs clarification
- Newbie friendliness
- 35/100