Adding WebsocketService with lambda initialization does not work
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
When trying to build this simple example from the README
public class Chat : WebSocketBehavior
{
private string _suffix;
public Chat()
: this(null) {
}
public Chat(string suffix) {
_suffix = suffix ?? String.Empty;
}
protected override void OnMessage(MessageEventArgs e) {
Sessions.Broadcast(e.Data + _suffix);
}
}
//...
private void CreateWebsocketServer() {
websocketServer = new WebSocketServer(_wsServerPort);
websocketServer.AddWebSocketService<Chat>("/ChatWithNyan", () => new Chat(" Nyan!"));
websocketServer.Start();
}
I get this error on the lambda:
Delegate 'Action<Chat>' does not take 0 arguments
It does the same if I take Example2 and uncomment those lines:
wssv.AddWebSocketService<Chat>("/Chat", () =>new Chat("Anon#") {...}
If I do not use the initialization with the lambda, the example runs fine (see below).
private void CreateWebsocketServer() {
websocketServer = new WebSocketServer(_wsServerPort);
wssv.AddWebSocketService<Chat> ("/Chat");
// websocketServer.AddWebSocketService<Chat>("/ChatWithNyan", () => new Chat(" Nyan!"));
websocketServer.Start();
}
I will need the initialization to pass some data to my WebsocketService. Do someone have any idea of what could be going wrong ? Thanks.
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 the AddWebSocketService method used in the README example and compare its available overloads with Example2. Reproduce the compiler error using the lambda-based initialization, then verify that the service can be created with the requested data and that the example still builds and runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100