sta / sta/websocket-sharp

Adding WebsocketService with lambda initialization does not work

Open
#677 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

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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.