sta / sta/websocket-sharp

Overriding events in WebSocket-Sharp client?

Open
#541 0 comments 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

Hi. My server is working fine with my

internal class ServerSocket : WebSocketBehavior

when i overrided methods like:

     protected override void OnMessage(MessageEventArgs e)
        {
            Send("Now, i starting to receeeive");
            var msg = e.Data;
            while (msg != "end")
            {
                Console.WriteLine("Send msg: \n");
                msg = Console.ReadLine();
                Send(msg);

            }

        }

        protected override void OnOpen()
        {
            Send("Hello conneted");
         
        }

        protected override void OnError(ErrorEventArgs e)
        {
            Console.WriteLine($"Eeerror {e.Message}");
            //Send(e.Message);
            //Console.WriteLine($"Error {e.Message} //send by server");
        }

        protected override void OnClose(CloseEventArgs e)
        {
            Send("Byeeeeeee //send by server");
        }

but when im using overriding methods in Client it cant handle any event

protected override void OnMessage(MessageEventArgs e)
        {
            Console.WriteLine(e.Data);
        }

        protected override void OnOpen()
        {

            JObject subscribe = new JObject();
            subscribe.Add("op", "subscribe");
            subscribe.Add("trades", "BTCUSD");
            subscribe.Add("args", "ALL");
            Send(subscribe.ToString());
        }

        protected override void OnError(ErrorEventArgs e)
        {
            Console.WriteLine($"Eeerror {e.Message}");

        }

        protected override void OnClose(CloseEventArgs e)
        {
            Send("unsubscribe");
        }


and i have to use it like in your example:

 soc.OnMessage += (sender, e) =>
            {
                Console.WriteLine(e.Data);
            };

            soc.OnOpen += (sender, e) =>
            {

            };

Why is it working like this? I dont think that im doing it wrong, because i did it exactly like with events in Server.

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

Review the client usage and the shown OnMessage/OnOpen overrides alongside the event-handler subscriptions in the issue. Reproduce the client connection and determine whether the override callbacks are invoked; done means explaining the difference or identifying a confirmed client-side defect.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.